题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

#include <stdio.h>
#include <string.h>
typedef struct studentStruct{
    int value;
    int number;
    char name[50];
}student;
int main() {
    student tableStudent[200];

    int N, arr;
    scanf("%d %d",&N,&arr);
    for (int i=0; i<N; i++) {
        scanf("%s %d",tableStudent[i].name,&tableStudent[i].value);
        tableStudent[i].number = i;
    }

    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            student tempStudent = tableStudent[i];
            if(!arr){
                if(tempStudent.value<tableStudent[j].value) {
                    tableStudent[i] = tableStudent[j];
                    tableStudent[j] = tempStudent;
                }
            }else{
                if(tempStudent.value>tableStudent[j].value) {
                    tableStudent[i] = tableStudent[j];
                    tableStudent[j] = tempStudent;
                }
            }
            
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            student tempStudent = tableStudent[i];
            if(tempStudent.value != tableStudent[j].value) continue;
            if(tempStudent.number > tableStudent[j].number) {
                    tableStudent[i] = tableStudent[j];
                    tableStudent[j] = tempStudent;
            }
        }
    }

    for (int i=0; i<N; i++) {
        printf("%s %d\n",tableStudent[i].name,tableStudent[i].value);
    }
    return 0;
}

全部评论

相关推荐

07-07 11:33
江南大学 Java
已经在暑假实习了&nbsp;,没有明确说有hc,纠结实习到八月份会不会有点影响秋招毕竟感觉今年好多提前批
程序员小白条:92的话准备提前批,其他没必要,没面试机会的,而且你要准备充分,尤其八股和算法题
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
06-19 10:54
门头沟学院 Java
绝迹的星:行情挺好的, 刚拒了一个美团offer, 因为不给配电动车
点赞 评论 收藏
分享
07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务