shengmin @ 2023-08-24 11:36:23
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long s(long long c){
x=c;
if(x%2==0){
cout<<x<<"/2="<<x/2<<endl;
x=x/2;
return x;
}else{
cout<<x<<"*3+1="<<x*3+1<<endl;
x=x*3+1;
return x;
}
return 0;
}
int main() {
cin>>n;
x=n;
for(int i=1;;i++){
s(x);
if(x==1)break;
}
cout << "End";
return 0;
}
by longlong2012 @ 2023-08-24 11:39:25
错的点是输出End,你再检查检查
by longlong2012 @ 2023-08-24 11:41:11
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long s(long long c){
x=c;
if(x%2==0){
cout<<x<<"/2="<<x/2<<endl;
x=x/2;
return x;
}else{
cout<<x<<"*3+1="<<x*3+1<<endl;
x=x*3+1;
return x;
}
return 0;
}
int main() {
cin>>n;
x=n;
if(n==1){
cout<<"End";
return 0;
}
for(int i=1;;i++){
s(x);
if(x==1){
break;
}
}
cout<<"End";
return 0;
}
by shengmin @ 2023-08-24 12:24:10
栓Q