From 0aeb20a8c50b20c46d645ba3e37fc37f845d8da0 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Mon, 25 Oct 2021 10:08:37 +0800 Subject: [PATCH] add exercises --- .../11_The Best Rank/desc.md" | 16 +++++-- .../11_The Best Rank/solution.cpp" | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git "a/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/desc.md" "b/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/desc.md" index d7c17c973..7c3f4df2b 100644 --- "a/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/desc.md" +++ "b/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/desc.md" @@ -1,8 +1,16 @@ ## 标题 - +结构体排序 ## 题目描述 - +输入学生名字和分数,对其降序排序 #### 输入 - +``` +zhangsan 100 +lisi 60 +wangwu 80 +``` #### 输出 - \ No newline at end of file +``` +zhangsan 100 +wangwu 80 +lisi 60 +``` \ No newline at end of file diff --git "a/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/solution.cpp" "b/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/solution.cpp" index e69de29bb..30e211afa 100644 --- "a/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/solution.cpp" +++ "b/data/2.\347\256\227\346\263\225\344\270\255\351\230\266/1.pat\347\224\262\347\272\247/11_The Best Rank/solution.cpp" @@ -0,0 +1,44 @@ +#include +#include +#define N 100 +using namespace std; +struct student +{ + string name; + int score; +}; +bool sortrule(student a, student b) +{ + if (a.score > b.score) + { + return true; + } + else if (a.score < b.score) + { + return false; + } + else if (a.score == b.score) + { + if (a.name < b.name) + return true; + else + return false; + } +} +int main() +{ + student stu[N]; + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> stu[i].name >> stu[i].score; + } + sort(stu, stu + n, sortrule); + for (int i = 0; i < n; i++) + { + cout << stu[i].name << " " << stu[i].score << endl; + } + + return 0; +} \ No newline at end of file -- GitLab