加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

PAT_A1141#PAT Ranking of Institutions

发布时间:2020-12-14 01:07:46 所属栏目:Linux 来源:网络整理
导读:? Source: PAT A1141?PAT Ranking of Institutions?(25?分) Description: After each PAT,the PAT Center will announce the ranking of institutions based on their students‘ performances. Now you are asked to generate the ranklist. Input Specific

?

Source:

PAT A1141?PAT Ranking of Institutions?(25?分)

Description:

After each PAT,the PAT Center will announce the ranking of institutions based on their students‘ performances. Now you are asked to generate the ranklist.

Input Specification:

Each input file contains one test case. For each case,the first line gives a positive integer N (≤),which is the number of testees. Then N lines follow,each gives the information of a testee in the following format:

ID Score School

where?ID?is a string of 6 characters with the first one representing the test level:?B?stands for the basic level,?A?the advanced level and?T?the top level;?Score?is an integer in [0,100]; and?School?is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that?ID?is unique for each testee.

Output Specification:

For each case,first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:

Rank School TWS Ns

where?Rank?is the rank (start from 1) of the institution;?School?is the institution code (all in lower case); ;?TWS?is the?total weighted score?which is defined to be the integer part of?ScoreB/1.5 + ScoreA + ScoreT*1.5,where?ScoreX?is the total score of the testees belong to this institution on level?X; and?Ns?is the total number of testees who belong to this institution.

The institutions are ranked according to their?TWS. If there is a tie,the institutions are supposed to have the same rank,and they shall be printed in ascending order of?Ns. If there is still a tie,they shall be printed in alphabetical order of their codes.

Sample Input:

10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu

Sample Output:

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

Keys:

  • map(C++ STL)
  • string(C++ STL)
  • 快乐模拟

Attention:

  • 字符串转换为小写:transform(s.begin(),s.end(),s.begin(),::tolower);
  • 字符串转换为大写:transform(s.begin(),::toupper);

Code:

 1 /*
 2 Data: 2019-05-24 09:43:26
 3 Problem: PAT_A1141#PAT Ranking of Institutions
 4 AC: 33:40
 5 
 6 题目大意:
 7 按分数排名
 8 输入:
 9 第一行给出,考试人数N<=1e5
10 接下来N行给出,ID(1位字母+5位数字),分数[0,100],学校(<=6,大小写敏感)
11 输出:
12 第一行输出,学校总数M
13 接下来M行,排名(>=1),学校(小写),总分(B/1.5+A+T*1.5),考生数
14 排序规则,总分递减,人数递增,学校字典序
15 */
16 
17 #include<cstdio>
18 #include<iostream>
19 #include<algorithm>
20 #include<map>
21 #include<string>
22 using namespace std;
23 const int M=1e5+10;
24 int pt=1;
25 struct node
26 {
27     string id;
28     double score;
29     int num;
30 }info[M];
31 map<string,int> mp;
32 
33 int ToInt(string s)
34 {
35     if(mp[s]==0)
36     {
37         mp[s]=pt;
38         info[pt].num=0;
39         info[pt].score=0;
40         info[pt].id=s;
41         return pt++;
42     }
43     else
44         return mp[s];
45 }
46 
47 bool cmp(node a,node b)
48 {
49     if((int)a.score != (int)b.score)
50         return a.score > b.score;
51     else if(a.num != b.num)
52         return a.num < b.num;
53     else
54         return a.id < b.id;
55 }
56 
57 int main()
58 {
59 #ifdef    ONLINE_JUDGE
60 #else
61     freopen("Test.txt","r",stdin);
62 #endif
63 
64     int n;
65     scanf("%d",&n);
66     for(int i=0; i<n; i++)
67     {
68         string id,stu;
69         double score;
70         cin >> id >> score >> stu;
71         transform(stu.begin(),stu.end(),stu.begin(),::tolower);
72         int sch = ToInt(stu);
73         if(id[0]==T)
74             score*=1.5;
75         else if(id[0]==B)
76             score/=1.5;
77         info[sch].score += score;
78         info[sch].num++;
79     }
80     sort(info+1,info+pt,cmp);
81     printf("%dn",pt-1);
82     int r=1;
83     for(int i=1; i<pt; i++)
84     {
85         if(i==1 || (int)info[i].score!=(int)info[i-1].score)
86             r=i;
87         cout<<r<< <<info[i].id<< <<(int)info[i].score<< <<info[i].num<<endl;
88     }
89 
90     return 0;
91 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读