Wednesday, January 3, 2018

UVa problem solution 10258 - Contest Scoreboard

problem link:

Discuss: though it's a implementation problem.i think pupil coder at least think for some time how to implement. however, you can solve the problem using nested structure.just take input and store in structure and then sort the structure.you can use bubble sort. there is no tricky part in this problem


try yourself,before see the code




#include<bits/stdc++.h>
using namespace std;
struct problem
    {
         int prob=0;
            bool status=true;
            int tim=0;
    };
struct sboard
{
    bool team=false;
    int penal=0;
    int solve=0;
    int number=0;
    struct problem po[10];

};
int main()
{
    //freopen("input.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    int cases;
    cin >>cases;
  while(cases--)
    {

   struct sboard tm[101];
   //struct sboard tm[100] problem po[10];
   int i,j,cnt=0,t,p,tt;
   char ch,line[50];
   scanf("\n");
    while(gets(line))
   {
      if(!strcmp(line, ""))
        break;
       sscanf(line, "%d %d %d %c", &t, &p, &tt,&ch);
       //cin >>t>>p>>tt>>ch;
        //cout <<t<<p<<tt<<ch;
       tm[t].team=true;
       tm[t].number=t;
       if(ch=='I')
       {
       tm[t].po[p].prob++;
       tm[t].po[p].tim+=20;
       }
       if(ch=='C'&&tm[t].po[p].status)
       {
          tm[t].penal+=tt+tm[t].po[p].tim;
          tm[t].solve++;
          tm[t].po[p].status=false;
       }
   }
   for(i=0;i<100;i++)
   {
       for(j=0;j<100-i;j++)
       {
           if(tm[j].solve<tm[j+1].solve)
           {
               swap(tm[j],tm[j+1]);
           }
           if((tm[j].solve==tm[j+1].solve)&&(tm[j].penal>tm[j+1].penal))
              {
                  swap(tm[j],tm[j+1]);
              }
       }
   }
   for(i=0;i<101;i++)
   {
       if(tm[i].team)

           cout <<tm[i].number<<' '<<tm[i].solve<<' '<<tm[i].penal<<endl;

   }
   if(cases)
   cout <<endl;
}
return 0;
}

No comments:

Post a Comment