ACM&Ranklist

题目描述:
    今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的考生,并将他们的成绩按降序打印。
输入:

    测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N < 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号(题目号由1到M)。 
    当读入的考生人数为0时,输入结束,该场考试不予处理。

输出:

    对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考号的升序输出。

样例输入:
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0
样例输出:
3
CS003 60
CS001 37
CS004 37
0
1
CS000000000000000002 20
http://ac.jobdu.com/problem.php?pid=1014
  1 #include <iostream>
  2 
  3 #include <string>
  4 
  5 #include <cstdlib>
  6 
  7 using namespace std;
  8 
  9  
 10 
 11 typedef struct Stu{
 12 
 13         string name;
 14 
 15         int result;
 16 
 17     } Stu;
 18 
 19  
 20 
 21 int comp(const void* p1, const void* p2);
 22 
 23  
 24 
 25 int main()
 26 
 27 {
 28 
 29     Stu stu[1005];
 30 
 31     int N,M,G;
 32 
 33     int score[15];
 34 
 35     int i,j,temp,k,x,count;
 36 
 37     while(cin>>N && N>0) {
 38 
 39         cin>>M>>G;
 40 
 41         for(i=0; i<M; i++)
 42 
 43             cin>>score[i];
 44 
 45         count=0;
 46 
 47         for(i=0; i<N; i++) {
 48 
 49             cin>>stu[i].name;
 50 
 51             cin>>k;
 52 
 53             temp=0;
 54 
 55             for(j=0; j<k; j++) {
 56 
 57                 cin>>x;
 58 
 59                 temp+=score[x-1];
 60 
 61             }
 62 
 63             if(temp>=G) count++;
 64 
 65             stu[i].result=temp;
 66 
 67         }
 68 
 69         cout<<count<<endl;
 70 
 71         qsort(stu, N,sizeof(Stu),comp);
 72 
 73         for(i=0; i<count; i++)
 74 
 75             cout<<stu[i].name<<" "<<stu[i].result<<endl;
 76 
 77     }
 78 
 79     return 0;
 80 
 81 }
 82 
 83  
 84 
 85 int comp(const void*p1, const void* p2) {
 86 
 87     const Stu *a = (const Stu*)p1;
 88 
 89     const Stu *b = (const Stu*)p2;
 90 
 91     if(a->result!=b->result)
 92 
 93         return b->result-a->result;
 94 
 95     else{
 96 
 97         if(a->name > b->name)
 98 
 99             return 1;
100 
101         else return -1;
102 
103      }
104 
105 }
main02.cpp
  1 using namespace std;
  2 
  3  
  4 
  5 void qsort(int result[], string name[], int begin, int end);
  6 
  7  
  8 
  9 void swap(int* a, int* b);
 10 
 11  
 12 
 13 int main()
 14 
 15 {
 16 
 17     string name[1005];
 18 
 19     int result[1005];
 20 
 21     int score[15];
 22 
 23     int N,M,G;
 24 
 25     int i,j,k,temp,count;
 26 
 27     while(cin>>N&&N>0) {
 28 
 29         cin>>M;
 30 
 31         cin>>G;
 32 
 33         for(i=0; i
 34 
 35             cin>>score[i];
 36 
 37         count=0;
 38 
 39         for(i=0; i
 40 
 41             cin>>name[i];
 42 
 43             cin>>k;
 44 
 45             result[i]=0;
 46 
 47             for(j=0; j
 48 
 49                 cin>>temp;
 50 
 51                 result[i]+=score[temp-1];
 52 
 53             }
 54 
 55             if(result[i]>=G) count++;
 56 
 57         }
 58 
 59  
 60 
 61  
 62 
 63         qsort(result, name, 0, N-1);
 64 
 65  
 66 
 67         cout<
 68 
 69  
 70 
 71             for(i=0;i
 72 
 73                 cout<
 74 
 75  
 76 
 77     }
 78 
 79     return 0;
 80 
 81 }
 82 
 83  
 84 
 85 void qsort(int result[], string name[], int begin, int end) {
 86 
 87     int compare, left, right;
 88 
 89     string temp = name[begin];
 90 
 91     compare=result[begin];
 92 
 93     left=begin;
 94 
 95     right=end;
 96 
 97     if(left>right) return ;
 98 
 99     while(left
100 
101         while((lefttemp)) right--;
102 
103  
104 
105             swap(&result[left], &result[right]);
106 
107             name[right].swap(name[left]);
108 
109  
110 
111         while((leftcompare) || (result[left]==compare && name[left]
112 
113  
114 
115             swap(&result[left], &result[right]);
116 
117             name[right].swap(name[left]);
118 
119  
120 
121     }
122 
123     result[right]=result[left];
124 
125     name[right]=name[left];
126 
127  
128 
129     qsort(result, name, begin, right-1);
130 
131     qsort(result, name, right+1,end);
132 
133 }
134 
135 void swap(int *a, int* b) {
136 
137     int temp;
138 
139     temp=*a;
140 
141     *a=*b;
142 
143     *b=temp;
144 
145 }
main03.cpp
  1 #include <iostream>
  2 #include <string>
  3 
  4 using namespace std;
  5 
  6 int main()
  7 
  8 {
  9 
 10     string name[1005];
 11 
 12     int result[1005];
 13 
 14     int score[15];
 15 
 16     int N,M,G;
 17 
 18     int i,j,k,temp,count;
 19 
 20     bool tag;
 21 
 22     while(cin>>N&&N>0) {
 23 
 24         cin>>M;
 25 
 26         cin>>G;
 27 
 28         for(i=0; i<M; i++)
 29 
 30             cin>>score[i];
 31 
 32         for(i=0; i<N; i++) {
 33 
 34             cin>>name[i];
 35 
 36             cin>>k;
 37 
 38             result[i]=0;
 39 
 40             for(j=0; j<k; j++) {
 41 
 42                 cin>>temp;
 43 
 44                 result[i]+=score[temp-1];
 45 
 46             }
 47 
 48         }
 49 
 50         //bubble,降序
 51 
 52          for(i=0,tag=true,count=0; tag; i++ ) {
 53 
 54             tag=false;
 55 
 56             for(j=N-1; j>i; j--) {
 57 
 58                 if(result[j]>result[j-1]) {
 59 
 60                     temp=result[j-1];
 61 
 62                     result[j-1]=result[j];
 63 
 64                     result[j]=temp;
 65 
 66                     name[j].swap(name[j-1]);
 67 
 68                 }
 69 
 70                 if(result[j]==result[j-1] && name[j]<name[j-1])
 71 
 72                     name[j].swap(name[j-1]);
 73 
 74 
 75 
 76             }
 77 
 78             if(result[i]>=G) { //当过线的学生排完后,低于分数线的人就不用排序了
 79 
 80                 count++;
 81 
 82                 tag=true;
 83 
 84             }
 85 
 86         }
 87 
 88         cout<<count<<endl;
 89 
 90         for(i=0;i<count;i++) {
 91 
 92             cout<<name[i]<<" "<<result[i]<<endl;
 93 
 94         }
 95 
 96     }
 97 
 98     return 0;
 99 
100 }
原文地址:https://www.cnblogs.com/wizzhangquan/p/2956076.html