标签:des style http color java 使用 os strong
/*
中文题意:
中文翻译:
题目大意:
解题思路:当n不为1的时候,用while循环,直到出现n为止,while循环很适合循环次数不确定时使用。
难点详解:对位运算的理解
关键点:位运算
解题人:lingnichong
解题时间:2014/08/01   15:41
解题感受:c语言学多了后,在参加竞赛时,取余的话都用n&1=0为偶数,n&1=1为奇数。
*/
3 1 0
5 0
#include<stdio.h>
int main()
{
	int n,s;
	while(scanf("%d",&n),n)
	{
		s=0;
		while(n!=1)
		{
			if(n&1)
			{
				n=n*3+1;
				n>>=1;
				s++;
			}
			else
			{
				n>>=1;
				s++;
			}
		}
		printf("%d\n",s);
	}
	return 0;
}  
标签:des style http color java 使用 os strong
原文地址:http://blog.csdn.net/qq_16767427/article/details/38337667