挑战编程 刘汝佳 的第一道习题 热身题
熟悉下提交格式
题意
1 #include <iostream> 2 #include <algorithm> 3 4 using namespace std; 5 6 int n, m; 7 8 9 10 11 12 13 int main() 14 { 15 while (cin >> n >> m) { 16 int start = min(n, m); 17 int end = max(n, m); 18 int maxcount = 0; 19 for (int i = start; i <= end; i++) { 20 long long tmp = i; 21 int count = 1; 22 while (tmp != 1) { 23 if (tmp & 1) { 24 //2 25 tmp = tmp * 3 + 1; 26 } 27 else { 28 //3 29 30 tmp = tmp >> 1; 31 } 32 count++; 33 } 34 35 if (maxcount < count) maxcount = count; 36 } 37 cout << n << " " << m << " " << maxcount << endl; 38 } 39 40 41 return 0; 42 }
原文地址:https://www.cnblogs.com/itdef/p/11525022.html
时间: 2024-10-10 01:24:07