zoukankan      html  css  js  c++  java
  • 1004. 成绩排名 (20)

    原题: https://www.patest.cn/contests/pat-b-practise/1004

    实现思路: 利用结构体定义学生信息, 简单循环即可实现功能. 注意, 本题最好不要使用
    结构指针.

    完整代码:

    #include <stdio.h>
    
    struct student {
        char name[20];
        char no[20];
        int score;
    };
    typedef struct student s_student; // 最好别用结构指针, 否则老麻烦了
    
    int main () {
        s_student high; // 最高的学生
        s_student low;  // 最低分学生
        s_student temp; // 遍历学生信息, 临时用
        int n;
    
        scanf("%d", &n);
        scanf("%s %s %d", high.name, high.no, &high.score);
        low = high; // 第一个数据, 作为初始值
        n--;
    
        while (n) {
            scanf("%s %s %d", temp.name, temp.no, &temp.score);
            if (high.score < temp.score) {
                high = temp;
            }
            if (low.score > temp.score) {
                low = temp;
            }
            n--;
        }
    
        printf("%s %s
    ", high.name, high.no);
        printf("%s %s
    ", low.name, low.no);
        return 0;
    }
    
    /*
    输入:
    3
    Joe Math990112 89
    Mike CS991301 100
    Mary EE990830 95
    
    输出:
    Mike CS991301
    Joe Math990112
    */
    
    
  • 相关阅读:
    模块化
    ES6中的let
    ES6中的块级作用域
    Mobile 移动端
    H5离线缓存
    nginx 配置步骤
    虚拟路径的配置
    Apache和php的相关配置
    TCP/IP协议
    PHP中的文件操作
  • 原文地址:https://www.cnblogs.com/asheng2016/p/7637784.html
Copyright © 2011-2022 走看看