3 1 0
5 0
解题遇到问题?分享解题心得?讨论本题请访问:http://t.jobdu.com/thread-7755-1-1.html
#include <iostream> using namespace std; int count = 0; void lala(int n) { if(n==1) cout<<0<<endl; else if(n%2==0) { n=n/2; count++; if(n==1) cout<<count<<endl; else lala(n); } else { n=(3*n+1)/2; count++; if(n==1) cout<<count<<endl; else lala(n); } } int main() { int k; while(cin>>k&&k!=0) { lala(k); count =0; } return 0; } /************************************************************** Problem: 1031 User: vhreal Language: C++ Result: Accepted Time:10 ms Memory:1520 kb ****************************************************************/
原文地址:http://blog.csdn.net/wtyvhreal/article/details/42212241