B - 验证角谷猜想 HDU - 1279
当时比赛提交一直都是PE,后来才知道是输出格式错误。
这题也很简单,记得期末考试考过。没有什么难点,唯一需要注意的是输出的格式。
AC代码如下:
#include<iostream>
using namespace std;
int main()
{
int n, num, c;
cin >> n;
while (n--)
{
c=0;
cin >>num;
while (num != 1)
{
if (num % 2!=0)
{
if (c == 0)
cout << num;
else
cout<<" "<<num;
c++;
num = num * 3 + 1;
}
else
num = num/2;
}
if (c==0)
cout << "No number can be output !";
cout << endl;
}
return 0;
}