3 条题解

  • 0
    @ 2025-12-25 16:17:32
    #include
    using namespace std;
    struct stu{
    	string name;
    	int x[4];
    	int sum = 0;
    };
    bool abc(stu x , stu y){
    	return x.sum > y.sum;
    }
    int main(){
    	int n;
    	cin >> n;
    	stu a[41];
    	for(int i = 0 ; i < n ; i ++){
    		cin >> a[i].name;
    		a[i].sum = 0;
    		for(int j = 0 ; j < 4 ; j ++){
    			cin >> a[i].x[j];
    			a[i].sum += a[i].x[j];
    		}
    	}
    	sort(a , a + n , abc);
    	for(int i = 0 ; i < 3 ; i ++){
    		cout << a[i].name << endl;
    	}
    	
    	
    	
    	
    	return 0;
    }
    
    • 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
        标签
        (无)
        递交数
        162
        已通过
        58
        上传者