我的代码为什么输出格式错误(杭州电子科技大学onlinejudge第1279题)?
#include<iostream>#include<cstdlib>usingnamespacestd;intmain(){intn,i,w,k;while(cin>>...
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n,i,w,k;
while (cin>>n)
{
w=0;
for (i=0;i<n;i++)
{
w=0;
cin>>k;
if (k%2==1 && k>1)w=2;
while (k>1)
{
if (k%2==1){if(w==2)cout<<k;else cout<<' '<<k;k=k*3+1;w=1;}
if (k%2==0){k/=2;}
}
if (w==0)cout<<"No number can be output !\n";
else cout<<endl;
}
}
//system("pause");
return 0;
} 展开
#include <cstdlib>
using namespace std;
int main()
{
int n,i,w,k;
while (cin>>n)
{
w=0;
for (i=0;i<n;i++)
{
w=0;
cin>>k;
if (k%2==1 && k>1)w=2;
while (k>1)
{
if (k%2==1){if(w==2)cout<<k;else cout<<' '<<k;k=k*3+1;w=1;}
if (k%2==0){k/=2;}
}
if (w==0)cout<<"No number can be output !\n";
else cout<<endl;
}
}
//system("pause");
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询