zoukankan      html  css  js  c++  java
  • UVa 10258

      题目大意:关于acm竞赛排名的题目,对于参赛者首先按做出的题目排名,然后是罚时,最后是编号。

      多关键字域排序问题。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cctype>
     4 #include <iostream>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 struct Cont
     9 {
    10     int id, num, t_penalty;
    11     int penalty[10];
    12     bool solved[10], join;
    13     bool operator < (const Cont & c) const
    14     {
    15         if (num != c.num)  return num > c.num;
    16         if (t_penalty != c.t_penalty)  return t_penalty < c.t_penalty;
    17         return id < c.id;
    18     }
    19 } cont[110];
    20 
    21 int main()
    22 {
    23 #ifdef LOCAL
    24     freopen("in", "r", stdin);
    25 #endif
    26     int T;
    27     scanf("%d", &T);
    28     getchar();
    29     char str[100];
    30     gets(str);
    31     while (T--)
    32     {
    33         memset(cont, 0, sizeof(cont));
    34         for (int i = 1; i <= 100; i++)
    35             cont[i].id = i;
    36         while (gets(str) && str[0])
    37         {
    38             int c, p, time;
    39             char ch;
    40             sscanf(str, "%d%d%d", &c, &p, &time);
    41             for (int i = strlen(str)-1; i >= 0; i++)
    42                 if (isupper(str[i]))
    43                 {
    44                     ch = str[i];
    45                     break;
    46                 }
    47             cont[c].join = true;
    48             if (ch == 'C')
    49             {
    50                 if (!cont[c].solved[p])
    51                 {
    52                     cont[c].num++;
    53                     cont[c].penalty[p] += time;
    54                     cont[c].solved[p] = true;
    55                 }
    56             }
    57             else if (ch == 'I')
    58             {
    59                 if (!cont[c].solved[p])
    60                     cont[c].penalty[p] += 20;
    61             }
    62         }
    63         for (int i = 1; i <= 100; i++)
    64             for (int j = 1; j <= 9; j++)
    65                 if (cont[i].solved[j])
    66                     cont[i].t_penalty += cont[i].penalty[j];
    67         sort(cont+1, cont+101);
    68         for (int i = 1; i <= 100; i++)
    69             if (cont[i].join)
    70                 printf("%d %d %d
    ", cont[i].id, cont[i].num, cont[i].t_penalty);
    71         if (T)  printf("
    ");
    72     }
    73     return 0;
    74 }
    View Code

      要注意的是,当一道题目正确提交后,以后对该题目的提交都对结果无影响。一直注意这点了,却忘了当一道题最终没有正确提交时,以前的错误提交是不计算罚时的,因为这个纠结了好长时间,WA的好惨...看别人代码时心里还在想“干嘛多次一举保存每个题的罚时?”,忽然就明白了,是我错了...

  • 相关阅读:
    最近几个月的感想
    Fortran 入门——C#调用Fortran DLL
    Fortran 入门——函数调用
    JQueryAjax初体验和一点感想
    【HDU】1796 How many integers can you find
    【SGU】476 Coach's Trouble
    【HDU】2204 Eddy's爱好
    【POJ】1091 跳蚤
    【URAL】1091 Tmutarakan Exams
    【ZOJ】2836 Number Puzzle
  • 原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3297740.html
Copyright © 2011-2022 走看看