我要被题目搞无语了

4. 小鲤鱼

XJOI - 题目ID:9370必做题100分

最新提交:

Wrong Answer

0 分

历史最高:

Wrong Answer

0 分

时间限制: 1000ms

空间限制: 524288kB

题目描述

小鲤鱼

【题目描述】

下面是一张与递归有关的图片,请仿照图片内容,参照样例,使用递归输出对应文字。(输出样例为中文会乱码,所以使用了体育老师教的不太规范的英文,请不要介意。)

[image]

【数据格式】

输入一个整数n表示拥抱的次数。

输出一串文字。

样例输入1:

1

样例输出1:

dog hug fish me

样例输入2:

3

样例输出2:

dog hug hug hug fish me me me
下面是我的代码
#include<bits/stdc++.h>
using namespace std;
int s=1;
void f(int n){
s++;
if(s==n+1)return ;
if(s==1)cout<<"dog ";
if(s<=(n+1)/2)cout<<"hug ";
if(s==(n+1)/2)cout<<"fish ";
if(s>n/2)cout<<"me ";
f(n);
}
int main(){
int n,m;
cin>>n;
f(n);
return 0;
}
哪位大神能帮帮我啊

4 个赞
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<"dog ";
	for(int i=1;i<=n;i++)cout<<"hug ";
	cout<<"fish";
	for(int i=1;i<=n;i++)cout<<" me ";

} 
5 个赞

我们老师说要用递归

6 个赞

等等题目上说要输出拥抱的次数

5 个赞

所以咱们都错了

5 个赞

不是输入

6 个赞

哦好吧

5 个赞


图片

6 个赞

用我的代码应该没错

5 个赞

先提交看看

5 个赞
s++;
if(s==1) cout<<"dog ";
else if(s<=n+1) cout<<"hug ";
else if(s==n+1+1) cout<<"fish";
else if(s<=(n+1)*2) cout<<"me";
f(n);
6 个赞

这样应该就好了

6 个赞

我的是对的

5 个赞

#include<bits/stdc++.h>
using namespace std;
int s=1;
void f(int n){
s++;
if(s==1) cout<<"dog ";
else if(s<=n+1) cout<<"hug ";
else if(s==n+1+1) cout<<“fish”;
else if(s<=(n+1)*2) cout<<“me”;
f(n);
}
int main(){
int n,m;
cin>>n;
f(n);
return 0;
}
这样TLE

6 个赞

好吧

6 个赞

@潘葛宇 用我的

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<"dog ";
	for(int i=1;i<=n;i++)cout<<"hug ";
	cout<<"fish";
	for(int i=1;i<=n;i++)cout<<" me ";

}

5 个赞
void f(int n){
	if(n==1){
		cout<<"hug fish me ";
        return ;
	}
	cout<<"hug ";
	f(n-1);
	cout<<"me ";
}
int main(){
	int n;
	cin>>n;
	cout<<"dog ";
	f(n);
    return 0;
}
6 个赞

个人特殊写法

6 个赞

谢谢了

6 个赞

@潘葛宇 用我的
她的会超时

5 个赞