当前位置:网站首页>1178 questions of Olympiad in informatics -- ranking of grades
1178 questions of Olympiad in informatics -- ranking of grades
2022-07-27 08:14:00 【Bamboo monk-】
【 Title Description 】
Give the transcript of a course in the class , Please sort your transcripts from high to low , If you have the same score, the smaller one in the name dictionary comes first .
【 Input 】
First act n (0 < n < 20), Indicates the number of students in the class ;
Next n That's ok , Each behavior, each student's name and his grades , Separate them with a single space . The name contains only letters and is no longer than 20, The score is no more than 100 Non-negative integer .
【 Output 】
Sort the transcripts from high to low and output them , Each line contains two items: name and score , There is a space between .
【 sample input 】
4 Kitty 80 Hanmeimei 90 Joey 92 Tim
【 sample output 】
Joey 92 Hanmeimei 90 Kitty 80 Tim 28
Examine the subject :
- Everyone has a name and grades , So use a structure
- The name is string type
Ideas :
There are two kinds of sorting rules , First, different grades , In descending order of grades ; Second, the results are the same , Descending by name ( Dictionary order )
Code :
#include<bits/stdc++.h>
using namespace std;
const int N=25;
struct node{
string name;
int score;
}a[N];
bool cmp(node x,node y)
{
if(x.score==y.score) return x.name<y.name;
return x.score>y.score;
}
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].score;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].name<<" "<<a[i].score<<endl;
}
return 0;
}边栏推荐
- docker 安装mysql后进入容器内部发现登录不了mysql
- Stored procedure trial 2 -- establish a test table to test different types of stored procedures
- PHP realizes data interaction with MySQL
- "PHP Basics" PHP statements and statement blocks
- 想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
- Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection
- Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
- Harbor can't log in with the correct password
- ERP生产作业控制 华夏
- [flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
猜你喜欢
Development of three database general SQL code based on PG Oracle and MySQL

DEMO:ST05 找文本ID 信息

Risk control and application of informatization project

【目标检测】YOLOv6理论解读+实践测试VisDrone数据集

Abstract factory pattern

擎创科技加入龙蜥社区,共建智能运维平台新生态

The seta 2020 international academic conference will be held soon. Welcome to attend!
![[MRCTF2020]PYWebsite 1](/img/d4/2d9cd06abd7188add668cde77d3075.png)
[MRCTF2020]PYWebsite 1

Record a PG master-slave setup and data synchronization performance test process
![API version control [eolink translation]](/img/3a/8a78e57a2474f33d011d91631fde74.jpg)
API version control [eolink translation]
随机推荐
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
I can't figure out why MySQL uses b+ trees for indexing?
Translation character '/b' in C #
On data security
Development of three database general SQL code based on PG Oracle and MySQL
C language: random number + Hill sort
Vcenter7.0 managing esxi7.0 hosts
Data extraction 1
CommonTitleBar hide left right
Use of string type "PHP Basics"
Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection
End of year summary
[pytorch] resnet18, resnet20, resnet34, resnet50 network structure and Implementation
Record a PG master-slave setup and data synchronization performance test process
Dormitory access control system made by imitating the boss (III)
You may need an additional loader to handle the result of these loaders.
[applet] how to get wechat applet code upload key?
Database startup report error_ user_ connect_ times &gt; 0 error
Stored procedure test 1 -- first acquaintance of love
C commissioned use cases