首页 > 其他分享 >1141 PAT Ranking of Institutions(附测试点5分析)

1141 PAT Ranking of Institutions(附测试点5分析)

时间:2023-09-04 17:56:31浏览次数:35  
标签:Ranking school 1141 name 测试点 int School TWS Ns

题目:

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 (≤105), 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

 

题目大意:给出每个学生的id、分数、学校,学校名称不区分大小写,输出学校排名、学校名称、总加权成绩、学校参赛人数。学校名称输出时候以小写方式输出。

 

思路:

1、因为要根据每个学校的多个属性对学校进行排序,因此将学校的信息使用结构体来存储

2、结构体数组的下标索引要和学校名字一一对应,这里使用map进行映射

3、测试点5要注意存TWS要用double存,比较,输出的时候用int

 

易错点

使用sort对结构体数组进行排序时,要注意数组的大小和下标是否从0开始

 

 

代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
struct School{
    string name;
    double TWS;
    int Ns, tws;
    School(){
        TWS = 0.0;
        Ns = 0;
    }
}school[100005];
map<string, int> mp;
bool cmp(School school1, School school2){
    if(school1.tws != school2.tws){
        return school1.tws > school2.tws;
    }
    else if(school1.Ns != school2.Ns){
        return school1.Ns < school2.Ns;
    }
    else{
        return school1.name < school2.name;
    }
}
int main(){
    int N, index = 0;
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        string id, name;
        int score;
        cin>>id>>score>>name;
        for(int j = 0; j < name.size(); j++){
            name[j] = tolower(name[j]);
        }
        if(!mp[name]){
            mp[name] = ++index;
        }
        int t = mp[name];
        school[t].name = name;
        school[t].Ns++;
        if(id[0] == 'T'){
            school[t].TWS = school[t].TWS + score * 1.0 * 1.5;
        }else if(id[0] == 'A'){
            school[t].TWS = school[t].TWS + score * 1.0;
        }else{
            school[t].TWS = school[t].TWS + score * 1.0 / 1.5;
        }
    }
    for(int i = 1; i <= index; i++){
        school[i].tws = (int)school[i].TWS;
    }
    sort(school + 1, school + index + 1, cmp);
    printf("%d\n", index);
    int rank = 1;
    for(int i = 1; i <= index; i++){
        if(i > 1 && school[i].tws < school[i - 1].tws){
            rank = i;
        }
        cout<<rank<<" "<<school[i].name<<" "<<school[i].tws<<" "<<school[i].Ns<<endl;
    }
}

 

标签:Ranking,school,1141,name,测试点,int,School,TWS,Ns
From: https://www.cnblogs.com/yccy/p/17677703.html

相关文章

  • 1142 Maximal Clique(附测试点1,3错误分析)
    题目:A clique isasubsetofverticesofanundirectedgraphsuchthateverytwodistinctverticesinthecliqueareadjacent.A maximalclique isacliquethatcannotbeextendedbyincludingonemoreadjacentvertex.(Quotedfromhttps://en.wikipedia.or......
  • app商城测试点
    原文:https://blog.csdn.net/qq_40807544/article/details/128287561购物车功能测试:1.页面是否与UI保持一致2.能否正常加入购物车3.账号未登录能否添加商品到购物车4.账号登录能否添加商品到购物车5.没有库存的商品是否可以加入购物车6.单个商品的数量上限最多能添加到购物车7.收......
  • STM32F103C8T6测试点亮小灯
    目录代码代码#include"stm32f10x.h"//Deviceheaderintmain(void){ // 寄存器操作,stm32有很多寄存器,操作不方便,推荐使用标准库或HAL库// RCC->APB2ENR=0x00000010;// GPIOC->CRH=0x00300000;// GPIOC->ODR=0x00002000; //注意:步骤二中,需引......
  • Web安全测试点
    随着因特网的不断发展,人们对网络的使用越来越频繁,通过网络进行购物、支付等其他业务操作。而一个潜在的问题是网络的安全性如何保证,一些黑客利用站点安全性的漏洞来窃取用户的信息,使用户的个人信息泄漏,所以站点的安全性变得很重要。Web系统的安全性测试包括以下内容:(1)Web漏洞......
  • 1141-查询近30天活跃用户数
    查询近30天活跃用户数原文地址:1141.查询近30天活跃用户数-力扣(LeetCode)题目如下所示个人题解这题主要考察MySQL中DATE数据类型的操作和GROUPBY用法。个人思考过程如下所示--1.建表CREATETABLE1141_Activity( user_idINT, session_idINT, activit......
  • 功能测试——web功能测试点
    WEB测试方法总结-笔记一、输入框1、字符型输入框:(1)字符型输入框:英文全角、英文半角、数字、空或者空格、特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号。禁止直接输入特殊字符时,使用“粘贴、拷贝”功能尝试输入。(2)长度检查:最小长度、最大长度、最小长度-1、最大长度+1、输入超......
  • 支付测试测试过程中需要注意的主要测试点及异常场景
    1.首先要保证接口都能正常调用; 2.生成一笔订单,支付完成后,同步或异步重复回调,只有一次有效;3.生成一笔订单,复制订单号和金额,再次生成一笔订单,用fiddler设置断点,用第一笔已完成订单号和订单金额去替换现有的订单号和金额,无法完成支付;4.生成一笔订单,跳转到第三方时修改金额,无法......
  • European software vendors ranking 2012 (zz)
    Europeansoftwarevendorsranking2012//z2013-07-1214:08:[email protected][T62,L646,R24,V1099]欧洲最大100家软件企业公司一百强100强软件公司世界欧洲美国最大营业额利润排名RankCompanyPublic ?CountryofHQlocationSoftwarereven......
  • 接口测试测试点__肖sir__测试点整理
    接口测试测试点==============================================================================================================================================================================================================================================......
  • 电梯的测试点__肖sir___整理测试点
    电梯的测试点===============================功能测试电梯内、外按键(包括上、下、楼层数、关闭按钮)正常响应且指示灯亮电梯正常上升、下降电梯门正常打开、关闭电梯所有按钮层数是否有效且可达电梯的承载量电梯空间大小电梯内的灯光电梯内的通风情况电梯的报警装置同一栋......