zoukankan      html  css  js  c++  java
  • poj1918

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

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

    简单题

    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;
    }
  • 相关阅读:
    test
    dd 命令 sd卡系统迁移
    关于庖丁分词
    Linux source命令
    Linux系统查看系统是32位还是64位方法总结 in 创新实训
    总结这两天连续干掉的bug In 创新实训 智能自然语言交流系
    穷举法应用——搬砖块
    判断素数类问题汇总
    统计计算学生成绩类问题汇总
    C语言简明数据类型指南
  • 原文地址:https://www.cnblogs.com/rainydays/p/2122977.html
Copyright © 2011-2022 走看看