PC/UVa:110101/100
题目很简单,注意读取i, j
后最好马上就打印出来,要不然把i, j
交换了之后再打印可能就有问题了。
#include <iostream>
using namespace std;
int main()
{
int i = 0, j = 0;
while (cin >> i >> j){
cout << i << ' ' << j << ' ';
if (i > j) i ^= j ^= i ^= j;
int max = 0;
for (int n = i; n <= j; n++)
{
int len = 1, res = n;
while (res != 1){
if (res & 0x1) res = 3 * res + 1;
else res >>= 1;
len++;
}
if (max < len) max = len;
}
cout << max << endl;
}
return 0;
}