UPC-人品指数

30 篇文章 8 订阅
14 篇文章 0 订阅

山再高,往上爬,总能登顶;
路再长,走下去,定能到达。

UPC-人品指数

题目描述

队员们都到齐了,大家先入住宾馆,由于扬州是著名的旅游城市,宾馆房间很难预订,节目组预订的房间有高级的和普通的。怎样分配房间成了一个很棘手的问题,技术控李晨提出用“人品指数”来决定房间的好坏,根据往期的节目中的表现来计算人品,比如撕掉别人的名牌的人加10分,玩某个游戏得第一名加5分,第二名加3分等等。当然也可以减分,比如没有及时救助队友减10分,玩某个游戏超时减5分等等。不过,一次扣分和加分的数值不会超过100。
计算每个队员的人品指数时,每人一行。一开始的时候会给每个队员的人品指数设为100。比如李晨的信息为:lichen:100-3-5+1+2-2,则他的人品指数为:93。
到底谁能得到宾馆的最好房间呢?

输入

输入有若干行(不超过100行)。每行为一个队员的信息,其中首先是一个姓名(不超过20个字符的字符串,只含有小写字母和空格),后面是一个冒号,再后面为类似于数学的加减式(其中没有多余空格,保证合法)表示一个队员的人品加减分情况。

输出

输出人品指数最高的队员名单。如果有多个队员的人品指数一样高,请按姓名的字典顺序全部输出(一行一个姓名)。

Sample Input

xiaoy:100-3-5+1+2-2
xiaox:100-10-20+1
xiaoz:100-50-50-1

Sample Output

xiaoy

Hint

对于100%的数据,队员的信息不超过100行。

思路分析
这个题的思路就是计算分数,然后存起来,排个序,输出就好
存起来就用struct 就好里面存储名字,分数就好
计算分数的过程可以先输入一个string。前面一直索取字符给名字。注意名字可能有空格的。
因为要跳过100这三个字符,还有一个符号
然后就循环打模拟,用n=n×10save[i]-'0’这个方法来存储数字。注意符号的问题
排序呢就是按照如果分数相同排名字,小的在前,如果不相同就分数大的在前
然后输出这就是输出所有排在最前面且相同的人。先输出一个,然后从下一个开始如果和上一个相同就继续输出。遇到第一个不同的就跳出

AC时间到

#include<algorithm>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<stdio.h>
#include<utility>
#include<vector>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#pragma warning(disable:4244)
#define PI 3.1415926536
#pragma GCC optimize(2)
#define accelerate cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll read() {
    ll c = getchar(), Nig = 1, x = 0;
    while (!isdigit(c) && c != '-')c = getchar();
    if (c == '-')Nig = -1, c = getchar();
    while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
    return Nig * x;
}
inline void out(ll a) {
    if (a < 0)putchar('-'), a = -a;
    if (a >= 10)out(a / 10);
    putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}
#define Floyd for(int k = 1; k <= n; k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
#define read read()
string temp;
struct node {
    string name;
    ll num;
}save[200];
bool cmp(node a, node b)
{
    if (a.num == b.num)return a.name < b.name;
    return a.num > b.num;
}
int main()
{
    accelerate;
    ll q = 0;
    while (getline(cin, temp))
    {
        int l = temp.size();
        int mark = 0;
        int i;
        for ( i = 0; i < l; i++)
        {
            if (temp[i] == ':') break;
            save[q].name += temp[i];
        }
        int ans = 0,res=0,t=1;
        for (i++; i < l; i++)
        {
            if (temp[i] >= '0' && temp[i] <= '9')ans = ans * 10 + temp[i] - '0';
            else
            {
                res += t * ans;
                ans = 0;
                if (temp[i] == '+')t = 1;
                else t = -1;
            }
        }
        res += t * ans;
        save[q++].num = res;
    }
    sort(save, save + q, cmp);
    cout << save[0].name << endl;
    for (ll i = 1; i < q; i++)
        if (save[i].num == save[i - 1].num)
        {
                cout << save[i].name << endl;
        }
        else break; 
         
}

By-轮月

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Round moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值