【题解】洛谷P1781宇宙总统 字符串+排序

题目链接
用stl进行字符串排序,注意比较函数先比长度再比大小

#include
#include
#include
#include
using namespace std;
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
struct node{
    int id;
    string vote;
}man[25];
int cmp(node a,node b)
{
    return a.vote.length()>b.vote.length()||(a.vote.length()==b.vote.length()&&a.vote>b.vote);
}
int main()
{
    //freopen("in.txt","r",stdin);
    int m;
    cin>>m;
    _rep(i,1,m)
    {
        cin>>man[i].vote;
        man[i].id=i;
    }
    sort(man+1,man+m+1,cmp);
    cout<1].id<1].vote<return 0;
}

你可能感兴趣的:(洛谷,排序,字符串)