这题没啥好说的,直接模拟
using namespace std; int T;
void Go(int& aa) { if(aa%2==0) aa=aa/2; else aa=aa*3+1; return; } void solve() { int n,step=1,amax; cin>>n;
amax=n; Go(n); amax=max(amax,n); while(n!=1) { Go(n); amax=max(amax,n); step++; } cout<<amax<<’ ‘<<step<<endl; } int main() { scanf(“%d”,&T); for(int step=0;step<T;step++) { printf(“case #%d:\n”,step); solve(); } return 0; }
题面好萌~~ [em:10][em:10]
这题没啥好说的,直接模拟
include
using namespace std;
int T;
void Go(int& aa)
{
if(aa%2==0) aa=aa/2;
else aa=aa*3+1;
return;
}
void solve()
{
int n,step=1,amax;
cin>>n;
amax=n;
Go(n);
amax=max(amax,n);
while(n!=1)
{
Go(n);
amax=max(amax,n);
step++;
}
cout<<amax<<’ ‘<<step<<endl;
}
int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}
题面好萌~~
[em:10][em:10]