EXCEL Sorting (Question 4 of Jiudu Tutorial)

insert image description here
Example Import:
3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
4 2
000007 James 85
000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010
A my 90 000001 Zoe 60 000002 James 90 0 0Export: Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90





















#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct E
{
    
    
    int number;
    char name[10];
    int score;

} a[1000];
bool c1(E a,E b)
{
    
    
    return a.number<b.number;
}
bool c2(E a,E b)
{
    
    
    int tmp=strcmp(a.name,b.name);
    if(tmp!=0)
        return tmp<0;
    else
        return a.number<b.number;
}
bool c3(E a,E b)
{
    
    
    if(a.score!=b.score)
        return a.score<b.score;
    else
        return a.number<b.number;
}

int main()
{
    
    
    int n,c;
    while(cin>>n)
    {
    
    
        if(n==0)
            break;
        cin>>c;
        for(int i=0; i<n; i++)
        {
    
    
            cin>>a[i].number>>a[i].name>>a[i].score;
        }

        if(c==1)
            sort(a,a+n,c1);
        else if(c==2)
            sort(a,a+n,c2);
        else
            sort(a,a+n,c3);
        cout<<"Case "<<c<<":"<<endl;
        for(int i=0; i<n; i++)
        {
    
    
            cout<<a[i].number<<" "<<a[i].name<<" "<<a[i].score<<endl;
        }
    }
    return 0;
}

Supongo que te gusta

Origin blog.csdn.net/weixin_44022810/article/details/106822601
Recomendado
Clasificación