题意:
清楚明了。
注意:
1.For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j
并没有说i<j一定成立;
2.The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
i 和 j一定要输入的顺序与输出的顺序一样。
于是就可以RE了!!!
View Code
#include<stdio.h> int main() { int n,m; int sum; int max; int i; int t,k; while(scanf("%d %d",&n,&m)!=EOF) { max=1; k=0; if(n>m){k=1;t=m;m=n;n=t;} for(int j=n;j<=m;j++) { i=j; sum=1; while(i!=1) { sum++; if(i%2==0)i/=2; else i=i*3+1; } if(sum>max)max=sum; } if(k==0)printf("%d %d %d\n",n,m,max); else printf("%d %d %d\n",m,n,max); } return 0; }