小P发现学校有校园歌唱赛,他想知道这次比赛的冠军是谁,请你帮他找出冠军选手。

7-10 10、 校园歌唱赛

小P发现学校有校园歌唱赛,他想知道这次比赛的冠军是谁,请你帮他找出冠军选手。

输入格式:
第一行输入一个整数N(N<1000),接下来输入N行数据,每行数据由两部分组成,学生姓名(少于30个字符)和得分(整数)。

输出格式:
输出获胜的学生姓名和得分。

输入样例:
在这里给出一组输入。例如:

8
zhangsan 3100
lisi 4800
wangwu 1000
zhaoliu 800
qianqi 900
sunming 1800
wudong 1000
yangxu 400
输出样例:
在这里给出相应的输出。例如:

lisi 4800

供参考:

#include <stdio.h>
struct student{
    char name[31];
    int  score;
}stu[1000];

int main()
{
    int n, i, max = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %d", stu[i].name, &stu[i].score);
        if (stu[i].score > stu[max].score)  max = i;
    }
    printf("%s %d", stu[max].name, stu[max].score);
    return 0;
}

该回答引用ChatGPT
参考下面的代码

#include <stdio.h>
#include <string.h>

#define MAXN 1000

typedef struct {
    char name[31];
    int score;
} Student;

int main() {
    int n, i;
    Student students[MAXN], *max_student = &students[0];

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %d", students[i].name, &students[i].score);
        if (students[i].score > max_student->score) {
            max_student = &students[i];
        }
    }

    printf("%s %d", max_student->name, max_student->score);

    return 0;
}


以下答案引用自GPT-3大模型,请合理使用:

。
解答:
#include<stdio.h>
int main(){
    int n;
    scanf("%d", &n);
    char winner[30];
    int score = 0;
    for(int i = 0; i < n; i++){
        char name[30];
        int tmpScore;
        scanf("%s%d", name, &tmpScore);
        if(tmpScore > score){
            strcpy(winner,name);
            score = tmpScore;
        }
    }
    printf("%s %d", winner, score);
    return 0;
}

如果我的回答解决了您的问题,请采纳我的回答