题目链接
https://www.patest.cn/contests/gplt/L2-027
思路
在输入的时候 判断分数 是否符合领取代金券条件 如果符合 SUM 就加上对应的代金券价值
然后在对名人堂排序的时候,要注意排名 以及分数相同时是按账号的字典序来排的
最好用C字符串 用SCANF 读入 不然有可能超时
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;
struct Node
{
char account[16];
int score;
int rank;
}q[maxn];
bool comp(Node x, Node y)
{
if (x.score == y.score)
return strcmp(x.account, y.account) < 0 ? 1 : 0;
return x.score > y.score;
}
int main()
{
int n, g, k;
scanf("%d%d%d", &n, &g, &k);
int sum = 0;
for (int i = 0; i < n; i++)
{
scanf(" %s%d", q[i].account, &q[i].score);
if (q[i].score >= g)
sum += 50;
else if (q[i].score >= 60)
sum += 20;
}
sort(q, q + n, comp);
printf("%d\n", sum);
q[0].rank = 1;
printf("%d %s %d\n", 1, q[0].account, q[0].score);
for (int i = 1; i < n; i++)
{
if (q[i].score == q[i - 1].score)
q[i].rank = q[i - 1].rank;
else
q[i].rank = i + 1;
if (q[i].rank > k)
break;
printf("%d %s %d\n", q[i].rank, q[i].account, q[i].score);
}
}