2 条题解

  • 0
    @ 2025-7-24 11:19:13
    #include<bits/stdc++.h> 
    using namespace std;
    struct stu{
        int cj;
        string name;
    };
    struct stu a[21];
    int main(){
    	struct stu t;
    	int q;
    	cin>>q;
    	for(int e=0;e<q;e++){
    		cin>>a[e].name>>a[e].cj;
    	}
    	for(int i=1;i<q;i++){
    		for(int j=0;j<q-i;j++){
    			if(a[j].cj<a[j+1].cj || (a[j].cj==a[j+1].cj && a[j].name>a[j+1].name)){
    				t=a[j];
    				a[j]=a[j+1];
    				a[j+1]=t;
                }
    		}
    	}
    	for(int w=0;w<q;w++){
    		cout<<a[w].name<<" "<<a[w].cj<<"\n";
    	}
    	return 0;
    }
    • 0
      using namespace std; 
      struct Student {
          string name;
          int score;
      };
      bool cmp(Student a, Student b) {
          if(a.score != b.score) return a.score > b.score;
          return a.name < b.name;
      }
      int main() {
          int n;
          cin >> n;
          vector<Student> students(n);
          for(int i=0; i<n; i++) {
              cin >> students[i].name >> students[i].score;
          }
          sort(students.begin(), students.end(), cmp);
          for(auto s : students) {
              cout << s.name << " " << s.score << endl;
          }
          return 0;
      }
      
      
    • 1

    信息

    ID
    182
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    86
    已通过
    18
    上传者