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

有没有大虾路过,进来看看呀,如此正确的代码怎么就WA呢,思路清晰。。

Posted by 123454321 at 2007-08-26 19:59:05 on Problem 3339
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

struct xxx
{
	int id;
	string name;
	char role;
	int sum;
}people[25],max;
int index[15];
int l,r;
int d,m,s;
bool cmp(struct xxx u,struct xxx v)
{
	if(u.role<v.role)
		return true;
	else if(u.role==v.role && u.id<v.id)
		return true;
	return false;
}
void deal()
{
	int i,k;
	int countD=0,countG=0,countM=0,countS=0;
	int flagD,flagG,flagM,flagS;
	int captain;
	sort(people+1,people+22+1,cmp);
	for(i=1;i<=22;i++)
	{
		if(people[i].role=='D')
		{
			if(countD==0)
				flagD=i;
			countD++;
		}
		else if(people[i].role=='G')
		{
			if(countG==0)
				flagG=i;
			countG++;
		}
		else if(people[i].role=='M')
		{
			if(countM==0)
				flagM=i;
			countM++;
		}
		else if(people[i].role=='S')
		{
			if(countS==0)
				flagS=i;
			countS++;
		}
	}
	if(countD<d ||countG<1 ||countM<m ||countS<s)
		printf("IMPOSSIBLE TO ARRANGE\n");
	else
	{
		index[1]=flagG;
		k=2;
		for(i=1;i<=d;i++)
			index[k++]=flagD+i-1;
		for(i=1;i<=m;i++)
			index[k++]=flagM+i-1;
		for(i=1;i<=s;i++)
			index[k++]=flagS+i-1;
		max.sum=-1;
		for(i=1;i<=11;i++)
		{
			if(people[index[i]].sum>=max.sum)
			{
				max.sum=people[index[i]].sum;
				captain=i;
			}
		}
		index[0]=index[captain];

		cout<<people[index[0]].id<<' '<<people[index[0]].name<<' '<<people[index[0]].role<<endl;
		cout<<people[index[1]].id<<' '<<people[index[1]].name<<' '<<people[index[1]].role<<endl;
		for(i=2;i<=11;i++)
			if(i==captain) 
				continue;
			else 
				cout<<people[index[i]].id<<' '<<people[index[i]].name<<' '<<people[index[i]].role<<endl;
	}
	printf("\n");
}
int main()
{
	int i;
	char tem;
	int x;
	while(scanf("%d",&x) && x)
	{
		for(i=1;i<=22;i++)
			people[i].sum=0;
		
		for(i=1;i<=22;i++)
		{
			if(i==1)
			{
				people[i].id=x;
				cin>>people[i].name;
			}
			else cin>>people[i].id>>people[i].name;
			getchar();
			people[i].role=getchar();
			while((tem=getchar())==' ')
			{
				scanf("%d",&l);
				getchar();
				scanf("%d",&r);
				people[i].sum+=r-l+1;
			}
		}
		scanf("%d",&d);getchar();
		scanf("%d",&m);getchar();
		scanf("%d",&s);

		deal();
	}
	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