POJ 1207

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     //freopen("acm.acm","r",stdin);
 7     int num_i;
 8     int num_j;
 9     int max;
10     int len;
11     int i;
12     int j;
13     int temp_i;
14     int temp_j;
15     while(cin>>num_i>>num_j)
16     {
17         temp_i = num_i;
18         temp_j = num_j;
19         if(num_i > num_j)
20         {
21             swap(num_i,num_j);
22         }
23         max = 0;
24         for(i = num_i; i <= num_j; ++ i)
25         {
26             j  = i;
27             len = 0;
28             while(j > 1)
29             {
30                 if(j%2 == 0)
31                 {
32                     j /= 2;
33                 }    
34                 else
35                 {
36                     j = 3*j + 1;
37                 }
38                 ++ len;
39             }
40             
41             if(len > max)
42             {
43                 max = len;
44             }
45         }
46         cout<<temp_i<<" "<<temp_j<<" "<<max+1<<endl;
47     }
48 }

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

原文地址:https://www.cnblogs.com/gavinsp/p/4563328.html