输出最高分数的学生姓名
输入学生的人数,然后再输入每位学生的分数和姓名,求获得最高分数的学生的姓名。
输入格式
第一行输入一个正整数 N(N≤100)N(N≤100),表示学生人数。接着输入 NN 行,每行格式如下:
分数 姓名
分数是一个非负整数,且小于等于 100100;
姓名为一个连续的字符串,中间没有空格,长度不超过 2020。
数据保证最高分只有一位同学。
输出格式
获得最高分数同学的姓名。
Sample Input
5 87 lilei 99 hanmeimei 97 lily 96 lucy 77 jim
Sample Output
hanmeimei
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
struct st{
int m;
char name[30];
}a,t;
int main()
{
int n,i,k;
t.m=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %s",&a.m,a.name);
if(a.m>t.m)
swap(a,t);
}
printf("%s",t.name);
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483402.html

浙公网安备 33010602011771号