题目
分析
本题的重点在于:对于以字符串表示的数字的排序,首先应该先看字符串长度:长度大的字符串(所代表的数字)更大。在字符串长度相同的前提下,可以按照字典序排序两个字符串(代表的数字)。
struct Candidate
{
int id;
string votes;
};
bool cmp(const Candidate& a, const Candidate& b)
{
if (a.votes.length() != b.votes.length())
{
return (a.votes.length() > b.votes.length());
}
else // 长度相等的字符串,进行字典序比较
{
return a.votes > b.votes;
}
}
答案

思考
(略)
