HDOJ 1279 验证角谷猜想(水)

来源:互联网 发布:java分布式系统 编辑:程序博客网 时间:2024/05/22 11:52

【思路】:水题。空格格式的控制和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 20int 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){//oddif (1 == n%2){if (1 == flag)cout << " " << n;elsecout << n;n = n*3+1;flag = 1;}//evenelse{n = n/2;}}if (0 == flag)cout << "No number can be output !";cout << endl; }return 0;}


0 0