64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int run(int n); //声明run函数
int main()
{
int a, m, n, e; //变量的命名要有好的习惯,不要用一些简单的字母表示,而且重要变量最好给加个注释
cin >> a;
for ( int i = 1; i <= a; i++ )
{
cin >> m >> n;
cout<<endl;
}
int p = run( m );
int q = run( n );
if ( p >= q )
{
e = p;
}
else
{
e = q;
}
for ( int j = 1; j <= a; j++ )
{
cout<< e <<endl;
}
//system("puase");
return 0;
}
int run( int n )
{
int count = 0;
while ( n != 1 )
{
if ( n % 2 == 0 )
{
n = n / 2;
}
else if ( n % 2 == 1 )
{
n = 3 * n + 1;
}
count++;
}
return count;
}