牛客练习赛15 沃老师学生的成绩


       题目链接: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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值