hdu 5131 梁山好漢

http://acm.hdu.edu.cn/showproblem.php?pid=5131

沒啥好說的

排序水題..

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
const int inf = 1000000000;
const int maxn = 205;
map<string , int> hash;
struct node{
    string s;
    int r,rr,mr;
}p[maxn];
int n,m;
bool cmp(node a,node b)
{
    if(a.r != b.r)
        return a.r > b.r;
    return a.s < b.s;
}
void work()
{
    hash.clear();
    for(int i = 0;i < n;++i)
        cin>>p[i].s,RD(p[i].r);
    RD(m);
    sort(p,p+n,cmp);
    int x = 1;
    p[0].rr = x++;hash[p[0].s] = 0;p[0].mr = 1;
    for(int i = 1;i < n;++i){
        hash[p[i].s] = i;
        if( p[i].r != p[i-1].r){
            x = 1;
            p[i].mr = i + 1;
        }
        else
            p[i].mr = p[i-1].mr;
        p[i].rr = x++;
    }
    for(int i = 0;i < n;++i){
        cout<<p[i].s;
        printf(" %d\n",p[i].r);
    }
    string t;
    while(m--){
        cin>>t;
        int i = hash[t];
        if(p[i].rr == 1)
            printf("%d\n",p[i].mr);
        else
            printf("%d %d\n",p[i].mr,p[i].rr);
    }
}
int main()
{
//    int _,cas = 1;
//    RD(_);
//    while(_--){
//        printf("Case #%d: %I64d\n",cas++,work());
//    }
    while(RD(n),n){
        work();
    }
    return 0;
}
/*

*/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章