1219 - Team Arrangement

All about problems in Volume 12. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
robin_0
New poster
Posts: 7
Joined: Tue Apr 28, 2015 9:47 am

Re: 1219 - Team Arrangement

Post by robin_0 » Thu Sep 10, 2015 4:19 pm

GETTING WA :(
HELP PLEASE :)

Code: Select all



#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define OUTPUT freopen("myfile.txt","w",stdout);
#define INPUT freopen("input.txt","r",stdin);


int main()
{
    int G_num[105],D_num[105],M_num[105],S_num[105],temp_num;
    int g,d,m,s;
    int form_d,form_m,form_s;
    char G_name[105][30],D_name[105][30],M_name[105][30],S_name[105][30],temp_name[30],pos[5];
    int G_age[105],D_age[105],M_age[105],S_age[105],temp_age;
    int i,j,len,tp=1,p;
    int team[11][3],max,captain,big,serial[11];
    char team_name[11][30],position[6]="GGDMS";

    char inp[20005];

    while(gets(inp))
    {
        if(!strcmp(inp,"0"))
            break;

        g=0;
        d=0;
        m=0;
        s=0;
        len=strlen(inp);

        temp_num=0;

        for(i=0;i<len;i++)
        {
            if(inp[i]==' ')
            {
                i++;
                break;
            }

            temp_num=temp_num*10+(inp[i]-'0');
        }

        /**Space remover */
        while(1)
        {
            if(inp[i]==' ')
                i++;
            else
                break;
        }

        j=0;

        for(;i<len;i++)
        {
            if(inp[i]==' ')
            {
                i++;
                break;
            }

            temp_name[j++]=inp[i];
        }
        temp_name[j]='\0';

        /**Space remover */
        while(1)
        {
            if(inp[i]==' ')
                i++;
            else
                break;
        }

        pos[0]=inp[i];

        /**Space remover */
        while(1)
        {
            if(inp[i]==' ')
                i++;
            else
                break;
        }

        temp_age=0;

        j=0;

        for(;i<len;i++)
        {
            if(inp[i]=='-')
            {
                temp_age-=j;
                j=0;
            }
            else if(inp[i]==' ')
            {
                temp_age+=j;
                j=0;
            }
            else
            {
                j=j*10+inp[i]-'0';
            }
        }
        temp_age+=j;

        if(pos[0]=='G')
        {
            G_num[g]=temp_num;
            strcpy(G_name[g],temp_name);
            G_age[g]=temp_age;
            g++;
        }

        else if(pos[0]=='D')
        {
            D_num[d]=temp_num;
            strcpy(D_name[d],temp_name);
            D_age[d]=temp_age;
            d++;
        }

        else if(pos[0]=='M')
        {
            M_num[m]=temp_num;
            strcpy(M_name[m],temp_name);
            M_age[m]=temp_age;
            m++;
        }

        else if(pos[0]=='S')
        {
            S_num[s]=temp_num;
            strcpy(S_name[s],temp_name);
            S_age[s]=temp_age;
            s++;
        }


        for(p=1;p<22;p++)
        {
            gets(inp);

            len=strlen(inp);

            temp_num=0;

            for(i=0;i<len;i++)
            {
                if(inp[i]==' ')
                {
                    i++;
                    break;
                }

                temp_num=temp_num*10+(inp[i]-'0');
            }

            /**Space remover */
            while(1)
            {
                if(inp[i]==' ')
                    i++;
                else
                    break;
            }

            j=0;

            for(;i<len;i++)
            {
                if(inp[i]==' ')
                {
                    i++;
                    break;
                }

                temp_name[j++]=inp[i];
            }
            temp_name[j]='\0';

            /**Space remover */
            while(1)
            {
                if(inp[i]==' ')
                    i++;
                else
                    break;
            }

            pos[0]=inp[i];

            /**Space remover */
            while(1)
            {
                if(inp[i]==' ')
                    i++;
                else
                    break;
            }

            temp_age=0;

            j=0;

            for(;i<len;i++)
            {
                if(inp[i]=='-')
                {
                    temp_age-=j;
                    j=0;
                }
                else if(inp[i]==' ')
                {
                    temp_age+=j;
                    j=0;
                }
                else
                {
                    j=j*10+inp[i]-'0';
                }

            }
            temp_age+=j;

            if(pos[0]=='G')
            {
                G_num[g]=temp_num;
                strcpy(G_name[g],temp_name);
                G_age[g]=temp_age;
                g++;
            }

            else if(pos[0]=='D')
            {
                D_num[d]=temp_num;
                strcpy(D_name[d],temp_name);
                D_age[d]=temp_age;
                d++;
            }

            else if(pos[0]=='M')
            {
                M_num[m]=temp_num;
                strcpy(M_name[m],temp_name);
                M_age[m]=temp_age;
                m++;
            }

            else if(pos[0]=='S')
            {
                S_num[s]=temp_num;
                strcpy(S_name[s],temp_name);
                S_age[s]=temp_age;
                s++;
            }
        }

        scanf("%d-%d-%d",&form_d,&form_m,&form_s);
        gets(inp);








        if(tp>1)
        printf("\n");
        tp++;
        if(((form_d+form_m+form_s)!=10)||(form_d>d)||(form_m>m)||(form_s>s))
            printf("IMPOSSIBLE TO ARRANGE\n");

        else
        {
            big=0;

            /** team selection G for 1 D for 2 M for 3 S for 4*/


            /**G sort*/

            {
                int sort_bank[500]={0,};
                for(i=0;i<g;i++)
                {
                    sort_bank[G_num[i]]=i+1;
                }

                i=0;
                for(j=0;j<1;j++)
                {
                    for(;i<500;i++)
                    {
                        if(sort_bank[i]!=0)
                        {
                            team[big][0]=1;      /**TYPE*/
                            team[big][1]=G_num[sort_bank[i]-1]; /**NUMBER*/
                            team[big][2]=G_age[sort_bank[i]-1]; /**AGE*/
                            strcpy(team_name[big],G_name[sort_bank[i]-1]); /**NAME*/
                            big++;
                            i++;

                            break;
                        }
                    }
                }
            }

            /**D sort*/

            {
                int sort_bank[500]={0,};
                for(i=0;i<d;i++)
                {
                    sort_bank[D_num[i]]=i+1;
                }

                i=0;
                for(j=0;j<form_d;j++)
                {
                    for(;i<500;i++)
                    {
                        if(sort_bank[i]!=0)
                        {
                            team[big][0]=2;      /**TYPE*/
                            team[big][1]=D_num[sort_bank[i]-1]; /**NUMBER*/
                            team[big][2]=D_age[sort_bank[i]-1]; /**AGE*/
                            strcpy(team_name[big],D_name[sort_bank[i]-1]); /**NAME*/
                            big++;
                            i++;

                            break;
                        }
                    }
                }
            }

            /**M sort*/

            {
                int sort_bank[500]={0,};
                for(i=0;i<m;i++)
                {
                    sort_bank[M_num[i]]=i+1;
                }

                i=0;
                for(j=0;j<form_m;j++)
                {
                    for(;i<500;i++)
                    {
                        if(sort_bank[i]!=0)
                        {
                            team[big][0]=3;      /**TYPE*/
                            team[big][1]=M_num[sort_bank[i]-1]; /**NUMBER*/
                            team[big][2]=M_age[sort_bank[i]-1]; /**AGE*/
                            strcpy(team_name[big],M_name[sort_bank[i]-1]); /**NAME*/
                            big++;
                            i++;

                            break;
                        }
                    }
                }
            }

            /**S sort*/

            {
                int sort_bank[500]={0,};
                for(i=0;i<s;i++)
                {
                    sort_bank[S_num[i]]=i+1;
                }

                i=0;
                for(j=0;j<form_s;j++)
                {
                    for(;i<500;i++)
                    {
                        if(sort_bank[i]!=0)
                        {
                            team[big][0]=4;      /**TYPE*/
                            team[big][1]=S_num[sort_bank[i]-1]; /**NUMBER*/
                            team[big][2]=S_age[sort_bank[i]-1]; /**AGE*/
                            strcpy(team_name[big],S_name[sort_bank[i]-1]); /**NAME*/
                            big++;
                            i++;

                            break;
                        }
                    }
                }
            }



            /**Find Captain*/
            max=0;
            big=0;

            for(i=0;i<11;i++)
            {
                if(team[i][2]>max)
                {
                    max=team[i][2];
                    big=team[i][1];
                    captain=i;
                }
                else if((team[i][2]==max)&&(big<team[i][1]))
                {
                    max=team[i][2];
                    big=team[i][1];
                    captain=i;
                }

            }

            printf("%d %s %c\n",team[captain][1],team_name[captain],position[team[captain][0]]);

            for(i=0;i<11;i++)
            {
                if(i==captain)
                    continue;
                else
                    printf("%d %s %c\n",team[i][1],team_name[i],position[team[i][0]]);

            }






        }


    }


    return 0;
}

anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 1219 - Team Arrangement

Post by anacharsis » Wed Jun 08, 2016 6:20 pm

The tricky ( annoying ) thing about this one is that how to compute "longest record with team" is underspecified.
Is it total years across all stints with team, or player with the longest spread of years ( possibly not continuous ) in his history with team?
I tried it both ways - figure out total years with team across all stints and use that to get AC.

Also, the way the data is presented, there isn't anything in the example data like 2000-2000.
So, I took that to mean that soccer seasons were like basketball seasons, where a single season is spread across two years.
If we take it this way, then a record that includes 2000-2001 and 2002-2003 would come to 2 seasons of tenure.
If each year actually counts as a season, then the above would actually count as 4 seasons.

To solve the problem, I used the second route: 2000-2001 and 2002-2003 counted as 4 seasons of tenure...

Post Reply

Return to “Volume 12 (1200-1299)”