Total Submission(s): 4484 Accepted Submission(s): 2300
4 5 9 16 11
5 9 7 11 17 13 5 No number can be output ! 11 17 13 5
解题思路:本题用简单思维即可解得,根据题目意思按要求输出相关结果即可。
#include<stdio.h> int main() { int n,j; int t; scanf("%d",&t); while(t--) { j=0; scanf("%d",&n); while(n!=1) //n!=1,循环继续 { if(n%2==0) n/=2; else //n为奇数,输出结果并处理 { if(!j) printf("%d",n),j=1; else printf(" %d",n); n=n*3+1; } } if(!j) printf("No number can be output !"); printf("\n"); } return 0; }