zoukankan      html  css  js  c++  java
  • 【HDOJ】5131 Song Jiang's rank list

    STL的使用。

     1 /* 5131 */
     2 #include <iostream>
     3 #include <map>
     4 #include <cstdio>
     5 #include <cstdlib>
     6 #include <cstring>
     7 #include <string>
     8 #include <algorithm>
     9 using namespace std;
    10 
    11 #define MAXN 205
    12 
    13 typedef struct {
    14     string s;
    15     int i, n;
    16 } hero_t;
    17 
    18 typedef struct node_t {
    19     int mmin, mmax;
    20     node_t() {}
    21     node_t(int a, int b) {
    22         mmin = a; mmax = b;
    23     }
    24 } node_t;
    25 
    26 hero_t heros[MAXN];
    27 
    28 bool comp(hero_t a, hero_t b) {
    29     if (a.n == b.n)
    30         return a.s < b.s;
    31     else
    32         return a.n > b.n;
    33 }
    34 
    35 int main() {
    36     int n, m;
    37     int i, j, k, id = 0;
    38     string s;
    39     node_t nd;
    40     
    41     ios::sync_with_stdio(false);
    42     
    43     #ifndef ONLINE_JUDGE
    44         freopen("data.in", "r", stdin);
    45     #endif
    46     
    47     while (cin>>n && n) {
    48         for (i=0; i<n; ++i) {
    49             heros[i].i = i;
    50             cin >>heros[i].s>>heros[i].n;
    51         }
    52         
    53         sort(heros, heros+n, comp);
    54         for (i=0; i<n; ++i)
    55             cout <<heros[i].s<<' '<<heros[i].n<<endl;
    56         
    57         map<string, node_t> tb;
    58         i = 0;
    59         while (i < n) {
    60             j = 1;
    61             while ((i+j)<n && heros[i+j].n == heros[i].n)
    62                 ++j;
    63             if (j > 1) {
    64                 for (k=0; k<j; ++k) {
    65                     tb[heros[i+k].s] = node_t(k+1, i+1);
    66                 }
    67                 i += j;
    68             } else {
    69                 tb[heros[i].s] = node_t(1, i+1);
    70                 ++i;
    71             }
    72         }
    73         cin >>m;
    74         while (m--) {
    75             cin >>s;
    76             nd = tb[s];
    77             if (nd.mmin == 1)
    78                 cout <<nd.mmax<<endl;
    79             else
    80                 cout <<nd.mmax<<' '<<nd.mmin<<endl;
    81         }
    82         id = 0;
    83     }
    84     
    85     return 0;
    86 }
  • 相关阅读:
    Spark Streaming反压机制
    spark submit参数及调优
    kafka中的配额管理(限速)机制
    Kafka限流
    BlockingQueue
    Android 更改userdata的大小
    visual studio 2019 error MSB3073 exited with code 1
    ARM 链接脚本分析
    Android Bluetooth hci 命令分析
    Android 查看蓝牙hci日志
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4184881.html
Copyright © 2011-2022 走看看