Squirrel_GZQ @ 2022-11-20 17:10:24
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==1) cout<<"End";
while(1){
if(n==2){
cout<<"2/2=1"<<endl;
break;
}
if(n%2!=0){
cout<<n<<'*'<<'3'<<'+'<<'1'<<'='<<n*3+1<<endl;
n=n*3+1;
}
else{
cout<<n<<'/'<<'2'<<'='<<n/2<<endl;
n=n/2;
}
}
cout<<"End";
return 0;
}
by Squirrel_GZQ @ 2022-11-20 17:12:12
我样例过了。
by MujicaSaki @ 2022-11-20 17:19:49
@Your_Name 如果n=1的话你这个程序会输出两个End吧。
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==1) {cout<<"End";return 0;}//修改处。
while(1){
if(n==2){
cout<<"2/2=1"<<endl;
break;
}
if(n%2!=0){
cout<<n<<'*'<<'3'<<'+'<<'1'<<'='<<n*3+1<<endl;
n=n*3+1;
}
else{
cout<<n<<'/'<<'2'<<'='<<n/2<<endl;
n=n/2;
}
}
cout<<"End";
return 0;
}
我没试应该可以AC。
by Squirrel_GZQ @ 2022-11-20 17:21:45
wow,红名大佬名不虚传!
by Squirrel_GZQ @ 2022-11-20 17:22:17
栓Q!
by Squirrel_GZQ @ 2022-11-20 17:23:46
实测已过
by lcy5419 @ 2022-11-20 17:25:45
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==1) cout<<"End";
else{
while(1){
if(n==2){
cout<<"2/2=1"<<endl;
break;
}
if(n%2!=0){
cout<<n<<'*'<<'3'<<'+'<<'1'<<'='<<n*3+1<<endl;
n=n*3+1;
}
else{
cout<<n<<'/'<<'2'<<'='<<n/2<<endl;
n=n/2;
}
}
cout<<"End";
}
return 0;
}
如果n!=1下面就不运行了
by Squirrel_GZQ @ 2022-11-26 17:51:31
@lmx100127 谢谢,过了,此帖到此结束!