一直跑出RE (SIGSEGV)
放在codeblocks跑沒問題,大小寫也對
請求高手解惑,謝謝
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{ while(cin>>n){
queue<int> q;
for(int i=0;i<n;i++){
q.push(i+1);
}
cout<<"Discarded cards: ";
while(q.size()!=1){
cout<<q.front();
if((q.size())>2) cout<<", ";
q.pop();
q.push(q.front());
q.pop();
}
cout<<endl;
cout<<"Remaining card: "<<q.front()<<endl;
}
}
一直跑出RE (SIGSEGV)
放在codeblocks跑沒問題,大小寫也對
請求高手解惑,謝謝
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{ while(cin>>n){
queue q;
for(int i=0;i<n;i++){
q.push(i+1);
}
cout<<"Discarded cards: ";
while(q.size()!=1){
cout<<q.front();
if((q.size())>2) cout<<", ";
q.pop();
q.push(q.front());
q.pop();
}
cout<<endl;
cout<<"Remaining card: "<<q.front()<<endl;
}
}
加入
if(n==0) break;
就解決了