#include <iostream> using namespace std; int main() { int n,stepNmub=0; while(scanf("%d",&n)!=EOF){ if(n==0) break;//0的情况 while(n!=1){ stepNmub++; if(n%2==0){ n/=2; } else{//不能写n%2==1? n=(3*n+1)/2; } } printf("%d",stepNmub); } }
#include <iostream> using namespace std; int main() { int n,stepNmub=0; while(scanf("%d",&n)!=EOF){ if(n==0) break;//0的情况 while(n!=1){ stepNmub++; if(n%2==0){ n/=2; } else{//不能写n%2==1? n=(3*n+1)/2; } } printf("%d",stepNmub); } }