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 tongkang at 2009-05-01 16:18:04 on Problem 2021
#include <iostream>
#include<string>
using namespace std;
int age[120],x;
struct Fa
{
    string fname;
    int fage;
}f[120];
struct Ch
{
    string cname;
    int cage;
}c[120];
int gfage(int i)
{
    if(f[i].fname=="Ted")
    {
        return f[i].fage=100;
    }
    else
    {
        for(int j=0;j<x;j++)
        {
            if(f[i].fname==c[j].cname)
            {
                if(f[j].fage==-1)
                gfage(j);
                return f[i].fage=f[j].fage-age[j];
            }
        }
    }
    return 0;
}
int main()
{
    int n,j,k,g,m,q;
    string tmpc;
    int tmpn,tep;
    int max,min;
    scanf("%d",&n);
    for(m=0;m<n;m++)
    {
        //初始化
        for(k=0;k<120;k++)
        {
//            f[k].fname="";
//            c[k].cname="";
            c[k].cage=-1;
            f[k].fage=-1;
        }
        //input
        scanf("%d",&x);
        for(g=0;g<x;g++)
        {
            cin>>f[g].fname;
            cin>>c[g].cname;
            scanf("%d",&age[g]);
        }
        //calculate
        for(j=0;j<x;j++)
        {
            gfage(j);
            c[j].cage=f[j].fage-age[j];
        }

        for(j=0;j<x-1;j++)
        {
            max=j;
            for(k=j+1;k<x;k++)
            {
                if(c[max].cage<c[k].cage)
                {
                    max=k;
                }
            }
            if(max!=j)
            {
//                    printf("XXXXXXXXXXXXXXX\n");
                tmpn=c[max].cage;
                tmpc=c[max].cname;
                c[max].cage=c[j].cage;
                c[max].cname=c[j].cname;
                c[j].cage=tmpn;
                c[j].cname=tmpc;
            }
        }


//        printf("XXXXXXXXXXXX\n\n");
//        printf("DATASET %d\n",m+1);
//        for(g=0;g<x;g++)
//        {
//            cout<<c[g].cname<<" ";
//
//            printf("%d\n",c[g].cage);
//        }
        j=1;
        k=0;
        while(j<=x)
        {

            tep=c[k].cage;
            if(j==x||tep!=c[j].cage)
            {
                for(g=k;g<j-1;g++)
                {
                    min=g;
                    for(q=k+1;q<j;q++)
                    {
                        if(c[min].cname.compare(c[q].cname)>0)
                        {
                            min=q;
                        }
                    }
                    if(min!=g)
                    {
//                        printf("XXXXXXXXXXXXXXX\n");
                        tmpc=c[min].cname;
                        c[min].cname=c[g].cname;
                        c[g].cname=tmpc;
                    }
                }
                k=j;
                j=k+1;
            }
            else
            {
                j++;
            }
        }
//        printf("result::\n\n");
       //output
        printf("DATASET %d\n",m+1);
        for(g=0;g<x;g++)
        {
            cout<<c[g].cname<<" ";

            printf("%d\n",c[g].cage);
        }
    }
    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