题目链接:https://www.nowcoder.com/acm/contest/83/B
这道题我当时没看见分数是小于等于10的一个数,然后就想复杂了。其实很简单,输入完成绩后只用判断后面有没有多余的零,所以我们在结构体里定义三个string,一个是名字,一个是输入的分数,还有一个是没有后面多余的零的分数,然后求出最后多余的零,得到没有多余的零的分数的字符串后一个sort就好了。
AC代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
struct Node{
string str;
string score;
string rel_score;
}Edge[300005];
int n;
bool cmp(Node &a,Node &b){
if(a.rel_score == b.rel_score){
return a.str < b.str;
}
return a.rel_score > b.rel_score;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++){
int flag = 0;
cin>>Edge[i].str>>Edge[i].score;
Edge[i].rel_score = Edge[i].score;
int ans = 0;
for(int j=Edge[i].rel_score.length()-1;j>=0;j--){
if(Edge[i].rel_score[j] == '0'){
ans++;
}
else break;
}
Edge[i].rel_score = Edge[i].rel_score.substr(0,Edge[i].rel_score.length() - ans);
}
sort(Edge,Edge+n,cmp);
for(int i=0;i<n;i++){
cout<<Edge[i].str<<" "<<Edge[i].score<<endl;
}
return 0;
}