poj1918

在使用printf时,%后面跟-号表示左对齐,否则右对齐。%后跟0表示用0补齐,否则表示用空格补齐,%后跟数字表示对齐宽度。

例如:%-05s,表示宽度为5右对齐输出s,左面空余区域用0补齐。

简单题

ContractedBlock.gif ExpandedBlockStart.gif View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 25
#define maxl 15
#define maxp 15

struct Team
{
int id, penalty;
int tot;
int rank;
} team[maxn];

int n, p, m;
char name[maxn][maxl];
bool solve[maxn][maxp];
int wrong[maxn][maxp];

int getid(char *st)
{
for (int i = 0; i < n; i++)
if (strcmp(name[i], st) == 0)
return i;
return -1;
}

void input()
{
scanf(
"%d", &n);
for (int i = 0; i < n; i++)
{
scanf(
"%s", name[i]);
team[i].id
= i;
team[i].penalty
= team[i].tot = 0;
}
scanf(
"%d%d", &p, &m);
memset(solve,
0, sizeof(solve));
memset(wrong,
0, sizeof(wrong));
for (int i = 0; i < m; i++)
{
int a, b;
char correct[maxl], t[maxl];
scanf(
"%d%d%s%s", &a, &b, correct, t);
int id = getid(t);
if (solve[id][a])
continue;
if (strcmp(correct, "Yes") == 0)
{
solve[id][a]
= true;
team[id].penalty
+= b + wrong[id][a] * 20;
team[id].tot
++;
continue;
}
wrong[id][a]
++;
}
}

bool operator <(const Team &a, const Team &b)
{
if (a.tot != b.tot)
return a.tot > b.tot;
if (a.penalty != b.penalty)
return a.penalty < b.penalty;
return strcmp(name[a.id], name[b.id]) < 0;
}

void work()
{
for (int i = 0; i < n; i++)
{
if (i == 0 || team[i].tot != team[i - 1].tot || team[i].penalty
!= team[i - 1].penalty)
team[i].rank
= i + 1;
else
team[i].rank
= team[i - 1].rank;
printf(
"%2d. %-8s% 2d% 5d\n", team[i].rank, name[team[i].id], team[i].tot, team[i].penalty);
}
}

int main()
{
//freopen("t.txt", "r", stdin);
int t;
scanf(
"%d", &t);
while (t--)
{
input();
sort(team, team
+ n);
work();
putchar(
'\n');
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值