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 ruiqi at 2007-08-14 21:36:12 on Problem 3339
#include <iostream>
using namespace std;

int num[30],year[30],k[5],u[5];
char name[30][30],x[30],y[5];
bool fg[30];
void doit()
{
    int i,j,l,kx,minnum,maxnum,maxyear;
    memset(fg,true,sizeof(fg));
    maxyear=maxnum=-1;
    for (i=1; i<=22; i++)
        if (year[i]>maxyear || year[i]==maxyear && num[i]>maxnum) 
        { maxyear=year[i]; maxnum=num[i]; kx=i; }
    cout<<num[kx]<<" "<<name[kx]<<" "<<x[kx]<<endl;
    fg[kx]=false;
	//cout<<endl;
	//for (i=1; i<=4; i++) cout<<y[i]<<"  "<<k[i]<<endl; 
	//cout<<endl;
    for (i=1; i<=4; i++)
        if (x[kx]==y[i]) k[i]--;
	//cout<<endl;
	//for (i=1; i<=4; i++) cout<<y[i]<<"  "<<k[i]<<endl; 
	//cout<<endl;
    for (i=1; i<=4; i++)
        for (j=1; j<=k[i]; j++)
        {
            minnum=1000;
            for (l=1; l<=22; l++)
                if (fg[l] && x[l]==y[i] && minnum>num[l])
                { minnum=num[l]; kx=l; }
            cout<<num[kx]<<" "<<name[kx]<<" "<<x[kx]<<endl;
            fg[kx]=false;
        }
}
int main()
{
    int i,j,a,b; char w; bool flag;
    y[1]='G'; y[2]='D'; y[3]='M'; y[4]='S';
    cin>>num[1];
    while (num[1]!=0)
    {
		memset(u,0,sizeof(u));
        cin>>name[1]>>x[1];
		for (i=1; i<=4; i++)
			if (x[1]==y[i]) u[i]++;
        year[1]=0;
        while ((w=getchar())!='\n')
        {
            scanf("%d-%d",&a,&b);
            year[1]+=b-a+1;
        }
        for (i=2; i<=22; i++)
        {
            cin>>num[i]>>name[i]>>x[i];
	    	for (j=1; j<=4; j++)
		    	if (x[i]==y[j]) u[j]++;
            year[i]=0;
            while ((w=getchar())!='\n')
            {
                scanf("%d-%d",&a,&b);
                year[i]+=b-a+1;
            }
        }
        k[1]=1;
        scanf("%d-%d-%d",&k[2],&k[3],&k[4]);
		//cout<<endl;
		//for (i=1; i<=22; i++) cout<<num[i]<<" "<<name[i]<<" "<<x[i]<<" "<<year[i]<<endl;
		//cout<<endl;
		//cout<<endl;
		//for (i=1; i<=4; i++)
		//	cout<<u[i]<<"  "<<k[i]<<endl;
		//cout<<endl;
		flag=true;
		for (i=1; i<=4; i++)
            if (u[i]<k[i]) flag=false;
        if (flag) doit();
		else cout<<"IMPOSSIBLE TO ARRANGE\n";
		cout<<endl;
		cin>>num[1];
	}
}

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