1 条题解

  • 0
    @ 2026-3-21 19:35:39

    学习一下这种输入方式

    
    #include<bits/stdc++.h>
    using namespace std;
    struct Student{
    	int score;
    	string name;
    };
    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> stu(n); //定义一个数据类型为 Student,大小为n的stu数组 
    	for(int i = 0;i < n;i++)
    	{
    		cin>>stu[i].name>>stu[i].score; 
    	}
    	sort(stu.begin(),stu.end(),cmp) ; //vector 排序的方法是使用 begin 
    	for(int i = 0;i < n;i++)
    	{
    		cout<<stu[i].name<<" "<<stu[i].score<<endl;
    	}
    	return 0;
    }
    
    

    信息

    ID
    354
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    330
    已通过
    118
    上传者