http://ac.jobdu.com/problem.php?id=1416
1 #include <stdio.h>
2 #include <algorithm>
3 #include <string.h>
4 using namespace std;
5 int n,m;
6 struct Monkey{
7 char name[101];
8 int stronger_level;
9 int food_to_eat;
10 int need;
11 }monkey[10005];
12 bool cmp(struct Monkey a,struct Monkey b)
13 {
14 if(a.stronger_level!=b.stronger_level){
15 return a.stronger_level>b.stronger_level;
16 }
17 return strcmp(a.name,b.name)<0;
18 }
19 int main()
20 {
21 while(scanf("%d%d",&n,&m)!=EOF){
22 int i;
23 for(i=0;i<n;i++){
24 scanf("%s%d%d",&monkey[i].name,&monkey[i].stronger_level,&monkey[i].food_to_eat);
25 }
26 sort(monkey,monkey+n,cmp);
27 int total=monkey[0].food_to_eat;
28 for(i=1;i<n;i++){
29 monkey[i].need=total;
30 total+=monkey[i].food_to_eat;
31 }
32 monkey[0].need=0;
33 int j;
34 char search_name[102];
35 for(i=0;i<m;i++){
36 scanf("%s",search_name);
37 for(j=0;j<n;j++){
38 if(strcmp(monkey[j].name,search_name)==0){
39 printf("%d\n",monkey[j].need+1);
40 break;
41 }
42 }
43 }
44 }
45 }