问题标题: 酷町堂:1172 打字游戏(game)

1
1

2
已采纳
黄俊博
黄俊博
资深光能
资深光能
老师说了,能用sort,所以就~~~~~~~
int comp(const game&a,const game&b)
{
    if(a.score.size()>b.score.size()) return 1;
    else
    if(a.score.size()<b.score.size()) return 0;
    else
    if(a.score>b.score) return 1;
    else
    if(a.score<b.score) return 0;
    else
    if(a.name>b.name) return 0;
    else
    if(a.name<b.name) return 1;
    return 1;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].name>>a[i].score;
    }
    sort(a+0,a+n,comp);

剩下的输出什么的补一下吧!

望采纳,谢谢。

黄俊博在2018-02-02 18:57:15追加了内容
#include<iostream> 
#include<algorithm>
#include<string>
using namespace std;
struct game{
    string name;
    string score;
}a[500];
int n;

 

 

 

 

 

 

 

    for(int i=0;i<n;i++)
    {
        cout<<a[i].name<<endl;
    }
    return 0;
}
0
0
0
储金洋
储金洋
新手光能
新手光能

用一个结构体里面两个字符串,一个放名字,还有一个放分数,还要一个long long类型的数组。

你再把放分数的字符串拆开,例如:123456———>1 2 3 4 5 6,接着把他们的ascii值累加到long long 类型的数组里,

然后就用结构体排序来从大到小排

0
我要回答