您的位置:首页 > 其它

CodeChef November Lunchtime 2013 Lucy and the Number Game(简单题)

2013-11-24 15:50 393 查看
n个人报数找到只有一个报过且最小的数。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define INF 0x7fffffff
#define LEN 1000100
using namespace std;

struct P{
char name[50];
int num;
}man[LEN];

bool cmp(struct P a, struct P b){
return a.num<b.num;
}

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

int T, n;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%s%d", man[i].name, &man[i].num);
}
sort(man+1, man+n+1, cmp);
int ans = -1, loc = man[1].num, cnt=1;
for(int i=2; i<=n; i++){
if(man[i].num == loc){
cnt++;
}
else {
if(cnt == 1){
ans = i-1;
break;
}else{
loc = man[i].num;
cnt = 1;
}
}
}
if(cnt == 1 && loc == man
.num) ans = n;
if(ans!=-1)printf("%s\n", man[ans].name);
else printf("Nobody wins.\n");
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: