【思路】:水题。空格格式的控制和No number can be output !的输出可以用一个flag来控制。
【AC代码】:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAX 20
int main(int argc, char** argv) {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int T = 0;
cin >> T;
while (T--)
{
int n = 0, flag = 0;
cin >> n;
while (n != 1)
{
//odd
if (1 == n%2)
{
if (1 == flag)
cout << " " << n;
else
cout << n;
n = n*3+1;
flag = 1;
}
//even
else
{
n = n/2;
}
}
if (0 == flag)
cout << "No number can be output !";
cout << endl;
}
return 0;
}