Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单的模拟编程。我用的单链表,有一点要注意的地方,我检查了好久,已注释出来。#include<iostream> #include<list> using namespace std; void show(list<int> l) { list<int>::iterator p; for(p=l.begin();p!=l.end();++p) cout<<*p<<" "; cout<<endl; } int main() { int n,x,i,j,k,num=0; int card[20]; list<int> l; while(cin>>n>>x) { for(i=0;i<20;++i) cin>>card[i]; for(i=1;i<=n;++i) l.push_back(i); i=0; list<int>::iterator p,q; while(1) { k=card[i]; p=l.begin(); j=1; while(1) { if(j==k) { q=p; //注意 p--; //这两步 l.erase(q); if(l.size()==x) break; j=0; } j++; p++; if(p==l.end()) break; } if(l.size()==x) break; i++; } cout<<"Selection #"<<++num<<endl; for(p=l.begin();p!=l.end();p++) if(p==l.begin()) cout<<*p; else cout<<" "<<*p; cout<<endl<<endl; l.clear(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator