Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

简单的模拟编程。我用的单链表,有一点要注意的地方,我检查了好久,已注释出来。

Posted by 139074241 at 2015-02-04 14:05:42 on Problem 1591
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator