hdu 4557 非诚勿扰

水题……

代码如下:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<iomanip>
 5 #include<cmath>
 6 #include<cstring>
 7 #include<vector>
 8 #define ll __int64
 9 #define pi acos(-1.0)
10 #define MAX 1001
11 using namespace std;
12 struct xx
13 {
14     int id;
15     char name[20];
16     int value;
17     bool use;
18 }an,p[1001];
19 bool cmp(const xx &a,const xx &b)
20 {
21     if(a.value==b.value)
22         return a.id<b.id;
23     return a.value<b.value;
24 }
25 char q[20];
26 int main(){
27     int t,n,i,j,k=0,v,num,top;
28     cin>>t;
29     while(t--){
30         cin>>n;
31         printf("Case #%d:
",++k);
32         num=0;top=0;
33         for(i=1;i<=n;i++){
34             scanf("%s",q);
35             if(q[0]=='A'){
36                 scanf("%s %d",&p[top].name,&p[top].value);
37                 p[top].id=top;
38                 p[top].use=false;
39                 num++;top++;
40                 printf("%d
",num);
41             }
42             else{
43                 scanf("%d",&v);
44                 sort(p,p+top,cmp);
45                 for(j=0;j<top;j++)
46                     if(!p[j].use&&p[j].value>=v){
47                         printf("%s
",p[j].name);
48                         p[j].use=true;
49                         num--;
50                         break;
51                     }
52                 if(j==top)
53                     printf("WAIT...
");
54             }
55         }
56     }
57     return 0;
58 }
View Code
原文地址:https://www.cnblogs.com/xin-hua/p/3252444.html