为什么这个程序在我自己编译器上运行正确,提交到uva网站上却是wrong answer?
#include<iostream>#include<queue>#include<cstring>usingnamespacestd;intmain(){intn;in...
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int main(){
int n;
int data[50];
queue <int> ori;
while(cin>>n&&n){
int i,j;
memset(data,0,50*sizeof(int));
while(!ori.empty())
ori.pop();
for(i=1;i<=n;i++)
ori.push(i);
for(i=0;ori.size()>1;i++){
data[i]=ori.front();
ori.pop();
ori.push(ori.front());
ori.pop();
}
cout<<"Discarded cards:";
for(j=0;j<i-1;j++)
cout<<data[j]<<',';
cout<<data[j]<<endl;
cout<<"Remaining card:"<<ori.front()<<endl;
}
return 0;
} 展开
#include<queue>
#include<cstring>
using namespace std;
int main(){
int n;
int data[50];
queue <int> ori;
while(cin>>n&&n){
int i,j;
memset(data,0,50*sizeof(int));
while(!ori.empty())
ori.pop();
for(i=1;i<=n;i++)
ori.push(i);
for(i=0;ori.size()>1;i++){
data[i]=ori.front();
ori.pop();
ori.push(ori.front());
ori.pop();
}
cout<<"Discarded cards:";
for(j=0;j<i-1;j++)
cout<<data[j]<<',';
cout<<data[j]<<endl;
cout<<"Remaining card:"<<ori.front()<<endl;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询