比赛 |
20120720 |
评测结果 |
AAATTTTTTT |
题目名称 |
忠诚点数榜 |
最终得分 |
30 |
用户昵称 |
苏轼 |
运行时间 |
1.416 s |
代码语言 |
C++ |
内存使用 |
3.17 MiB |
提交时间 |
2012-07-20 11:24:00 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- int number;
- struct hehe
- {
- string s;
- int fen;
- int jin;
- }w[250000];
- int sc=0;
- int cmp(const void *a,const void *b)
- {
- struct hehe *c=(struct hehe *)a;
- struct hehe *d=(struct hehe *)b;
- if(c->fen != d->fen) return d->fen - c->fen;
- else if (c->fen == d-> fen) return c-> jin - d->jin;
- }
-
- int main()
- {
- freopen ("lp.in","r",stdin);
- freopen ("lp.out","w",stdout);
- scanf("%d\n",&number);
- for (int p=0;p<number;p++)
- {
- int lq;
- char q[100];
- gets(q);
- lq=strlen(q);
- if (q[0]=='+')
- {
- string str;
- int i=1;
- while (q[i]!=' ')
- {
- str+=q[i];
- i++;
- }
- int o=-1;
- for (int i=0;i<sc;i++)
- {
- if (w[i].s==str)
- {
- o=i;
- break;
- }
- }
- i++;
- int num=0;
- while (i<lq)
- {
- num*=10;
- num+=q[i]-'0';
- i++;
- }
- if (o==-1)
- {
- w[sc].s=str;
- w[sc].fen=num;
- w[sc].jin=sc;
- sc++;
- }
- else
- {
- w[o].fen=num;
- }
- continue;
- }
- if (q[0]=='?'&&q[1]>='0'&&q[1]<='9')
- {
- int num=0;
- int i=1;
- while (i<lq)
- {
- num*=10;
- num+=q[i]-'0';
- i++;
- }
- qsort(w,sc,sizeof(w[0]),cmp);
- for (i=num-1;i<num+9&&i<sc;i++)
- {
- cout<<w[i].s<<' ';
- }
- cout<<endl;
- }
- else
- {
- string str;
- int i=1;
- while (q[i]!=' '&&i<lq)
- {
- str+=q[i];
- i++;
- }
- qsort(w,sc,sizeof(w[0]),cmp);
- for (int i=0;i<sc;i++)
- {
- if (w[i].s==str)
- {
- cout<<i+1<<endl;
- break;
- }
- }
- }
- }
- return 0;
- }