问题: 没有理解正确,误认为输入的两个数字是从小到大排列。
#include <stdio.h>
#include <stdlib.h>
int calc(int n){
int res = 1;
while(n!=1){
if(n%2==1) n = 3*n + 1;
else n = n/2;
res += 1;
}
return res;
}
int main(void){
int p,q;
while(scanf("%d %d", &p,&q) != EOF){
int i,k;
int m = (p<q)?p:q;
int n = (p+q)-m;
int tot = calc(m);
for(i=m+1;i<=n; i++){
k = calc(i);
if(k > tot)
tot = k;
}
printf("%d %d %d\n", p, q, tot);
}
/* system("pause");*/
return 0;
}