清华大学-成绩排序(排序+解决MLE问题)

成绩排序

成绩排序

  • 这里需要注意的就是超内存的问题。
  • 解决方法就是通过指针的方式,每次动态开n大小的内存,而不是一开始就分配。
#include
using namespace std;
int n;
const int maxn=1e6+6;
struct node{
    string name;
    int score;
    int level;
};
bool cmp1(const node& a,const node& b){//升序
    if(a.score==b.score){
        return a.levelb.score;
}
//node stu[maxn];
int main(){
    int kind;
    while(cin>>n>>kind){
        string s;
        node *stu=new node[n];
        int score;
        for(int i=0;i>s>>score;
            stu[i].name=s;
            stu[i].score=score;
            stu[i].level=i;
        }
        if(kind==0){
            sort(stu,stu+n,cmp2);
        }else{
            sort(stu,stu+n,cmp1);
        }
        for(int i=0;i

转载于:https://www.cnblogs.com/GarrettWale/p/11521432.html

你可能感兴趣的:(清华大学-成绩排序(排序+解决MLE问题))