2 条题解

  • 0
    @ 2025-1-12 16:11:23
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    int main() {
        int n;
        cin >> n; 
        vector<pair<string, int>> students; 
        for (int i = 0; i < n; ++i) {
            string name;
            int math, chinese, english, geography;
            cin >> name >> math >> chinese >> english >> geography;
            int total_score = math + chinese + english + geography;
            students.emplace_back(name, total_score);
        }
        sort(students.begin(), students.end(), [](const pair<string, int>& a, const pair<string, int>& b) {
            return a.second > b.second; 
        });
        for (int i = 0; i < 3; ++i) {
            cout << students[i].first << endl; 
        }
        return 0;
    }
    
    • 0
      @ 2023-9-26 17:23:43

      #include<bits/stdc++.h> using namespace std; struct sb { string name; int a; int b; int c; int d; int sum=0; }; bool sb114514(sb x,sb y) { if(x.sum>y.sum) { return 1; } return 0; } int main() { int n; cin>>n; sb j[n]; for(int i=0;i<n;i++) { cin>>j[i].name>>j[i].a>>j[i].b>>j[i].c>>j[i].d; j[i].sum=j[i].a+j[i].b+j[i].c+j[i].d; } sort(j,j+n,sb114514); for(int i=0;i<3;i++) { cout<<j[i].name<<endl; } return 0; }

      • 1

      信息

      ID
      119
      时间
      1000ms
      内存
      256MiB
      难度
      5
      标签
      (无)
      递交数
      144
      已通过
      53
      上传者