排序,结构体排序,大小排序

Problem  F

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3   Accepted Submission(s) : 2

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

“Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course. There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50. Note, only 1 student will get the score 95 when 3 students have solved 4 problems. I wish you all can pass the exam! Come on!

Input

Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume that all data are different when 0<p. A test case starting with a negative integer terminates the input and this test case should not to be processed.

Output

Output the scores of N students in N lines for each case, and there is a blank line after each case.

Sample Input

4
5 06:30:17
4 07:31:27
4 08:12:12
4 05:23:13
1
5 06:30:17
-1

Sample Output

100
90
90
95

100

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    char a[100][9];
    int b[100],c[100],d[6],N,i,j,f;
    while(cin>>N)
    if(N>-1)
    {
        memset(d,0,sizeof(d));
        for(i=0;i<N;i++)
        {cin>>b[i]>>a[i];
        switch(b[i])
        {
        case 5:d[5]++;break;
        case 4:d[4]++;break;
        case 3:d[3]++;break;
        case 2:d[2]++;break;
        case 1:d[1]++;break;
        }
        memset(c,0,sizeof(c));
        }
        for(i=0;i<N;i++)
            for(int j=0;j<N;j++)
                if(strcmp(a[i],a[j])>0&&b[i]==b[j])c[i]++;
        for(i=0;i<N;i++)
        {
        switch(b[i])
        {
            case 5:cout<<100<<endl;break;
            case 4:if(c[i]<d[4]/2)cout<<95<<endl;
                else cout<<90<<endl;break;
            case 3:if(c[i]<d[3]/2)cout<<85<<endl;
                else cout<<80<<endl;break;
            case 2:if(c[i]<d[2]/2)cout<<75<<endl;
                else cout<<70<<endl;break;
            case 1:if(c[i]<d[1]/2)cout<<65<<endl;
                else cout<<60<<endl;break;
            default:cout<<50<<endl;break;
        }
  }
        cout<<endl;
    }
    return 0;
}
我写的

#include <iostream>

#include <stdio.h>

#include <string.h>

#include <algorithm>

using namespace std

; int main()

{    

int t,save[6][2]={50,50,60,65,70,75,80,85,90,95,100,100},j,i,h,g,temp[100],a1[100],a[100],ans[1000],k;  

   char c[100][1000];    

while(scanf("%d",&t))  

   {        

if(t<=0)    

     break;     

    memset(a1,0,sizeof(a1));     

    memset(temp,0,sizeof(temp));

        for(h=0;h<t;h++)     

    {         

    scanf("%d",&a[h]);

            j=a[h];         

    a1[j]++;        

         cin>>c[h];     

    }          

   for(i=0;i<t;i++)      

          for(g=0;g<t;g++)    

              if(strcmp(c[i],c[g])>0&&a[i]==a[g])temp[i]++;  

                  for(i=0;i<t;i++)    

             {             

        k=a[i];            

           if(temp[i]<a1[k]/2)            

                  ans[i]=save[k][1];        

                 else                    

         ans[i]=save[k][0];      

           }              

   for(i=0;i<t;i++)               

      cout<<ans[i]<<endl;        

         cout<<endl;     

    }

    return 0;

}

   

#include <iostream>

#include <stdio.h>

#include<string.h>

#include <algorithm>

using namespace std;

struct node {   

  int index;     int score;     int p,t;   

  bool  operator<(const node&a)const;

};node a[103];

bool node:: operator<(const node&b)const

{     if(b.p==p)      return t<b.t;     return p>b.p; }

bool cmp1(const node&a,const node&b)

{     return a.index<b.index;

} int hash[6];

int main() {    

int i,j,n;    

int h,m,s;    

while(scanf("%d",&n),n!=-1)   

  {      

   memset(hash,0,sizeof(hash));    

     for(i=0;i<n;i++)      

   {            

scanf("%d %d:%d:%d",&a[i].p,&h,&m,&s);    

         hash[a[i].p]++;     

        a[i].t=h*3600+m*60+s;       

      a[i].index=i;     

    }     

sort(a,a+n);   

   i=0;   

   while(a[i].p==5)     

   a[i++].score=100;  

    for(j=0;j<hash[4]/2;j++)  

       a[i++].score=95;   

   for(;j<hash[4];j++)      

   a[i++].score=90;

      for(j=0;j<hash[3]/2;j++)    

     a[i++].score=85;      

for(;j<hash[3];j++)      

  a[i++].score=80;   

   for(j=0;j<hash[2]/2;j++)      

  a[i++].score=75;  

    for(;j<hash[2];j++)    

   a[i++].score=70;   

  for(j=0;j<hash[1]/2;j++)   

     a[i++].score=65;  

    for(;j<hash[1];j++)    

   a[i++].score=60;   

   for(;i<n;i++)     

   a[i].score=50;  

    sort(a,a+n,cmp1);   

   for(i=0;i<n;i++)    

   printf("%d\n",a[i].score);  

    printf("\n");   

  }    

return 0;

}

 

 

 

posted @ 2012-07-29 19:56  myth_HG  阅读(408)  评论(0编辑  收藏  举报