【HDOJ】5131 Song Jiang's rank list

STL的使用。

 /* 5131 */
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; #define MAXN 205 typedef struct {
string s;
int i, n;
} hero_t; typedef struct node_t {
int mmin, mmax;
node_t() {}
node_t(int a, int b) {
mmin = a; mmax = b;
}
} node_t; hero_t heros[MAXN]; bool comp(hero_t a, hero_t b) {
if (a.n == b.n)
return a.s < b.s;
else
return a.n > b.n;
} int main() {
int n, m;
int i, j, k, id = ;
string s;
node_t nd; ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (cin>>n && n) {
for (i=; i<n; ++i) {
heros[i].i = i;
cin >>heros[i].s>>heros[i].n;
} sort(heros, heros+n, comp);
for (i=; i<n; ++i)
cout <<heros[i].s<<' '<<heros[i].n<<endl; map<string, node_t> tb;
i = ;
while (i < n) {
j = ;
while ((i+j)<n && heros[i+j].n == heros[i].n)
++j;
if (j > ) {
for (k=; k<j; ++k) {
tb[heros[i+k].s] = node_t(k+, i+);
}
i += j;
} else {
tb[heros[i].s] = node_t(, i+);
++i;
}
}
cin >>m;
while (m--) {
cin >>s;
nd = tb[s];
if (nd.mmin == )
cout <<nd.mmax<<endl;
else
cout <<nd.mmax<<' '<<nd.mmin<<endl;
}
id = ;
} return ;
}
上一篇:java之集合类框架的简要知识点:泛型的类型擦除


下一篇:[Bootstrap]7天深入Bootstrap(3)CSS布局