您的位置:首页 > 其它

hdu1718 Rank

2015-11-15 16:39 387 查看
#include <stdio.h>

#include <string.h>

#include <cstring>

#include <iostream>

using namespace std;

int main()

{

//freopen("in.txt","r",stdin);

int sco[105], ans, pri, a, b, i, j, N;

char st[1005][100], st0[100], cmp[100];

while(cin >> st0)

{

a = b = N = 0;

pri = 0;

while(~scanf("%s%d", &st[a], &sco[b]) && strcmp(st[a], "0") && sco[b] != 0)

{

a++;

b++;

N++;

}

for(i = 0; i < N; i++)

for(j = 0; j < N - i - 1; j++)

{

if(sco[j] > sco[j+1])

{

int t = sco[j];

sco[j] = sco[j+1];

sco[j+1] = t;

strcpy(cmp, st[j]);

strcpy(st[j], st[j + 1]);

strcpy(st[j + 1], cmp);

}

}

for(int k = 0; k < N; k++)

if(!strcmp(st[k], st0)) { ans = k; break; }

for(i = N - 1; i >= 0; i--)

{

if(sco[i] > sco[ans]) pri++;

else break;

}

printf("%d\n", pri + 1);

memset(sco, 0, sizeof(sco));

memset(st, 0, sizeof(st));

memset(st0, 0, sizeof(st0));

memset(cmp, 0, sizeof(cmp));

}

return 0;

}

心得:做完六级水到题,结果手好生。。。好歹a了。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: