poj2643
简单题
View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 25
#define maxl 100
struct Candidate
{
int num;
int id;
} can[maxn];
int n, m;
char name[maxn][maxl];
char party[maxn][maxl];
bool operator <(const Candidate &a, const Candidate &b)
{
return a.num > b.num;
}
int getid(char *st)
{
for (int i = 0; i < n; i++)
if (strcmp(st, name[i]) == 0)
return i;
return -1;
}
void input()
{
char st[maxl];
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++)
{
gets(name[i]);
gets(party[i]);
can[i].id = i;
can[i].num = 0;
}
scanf("%d", &m);
getchar();
for (int i = 0; i < m; i++)
{
gets(st);
can[getid(st)].num++;
}
}
int main()
{
//freopen("t.txt", "r", stdin);
input();
sort(can, can + n);
if (n > 1 && can[0].num == can[1].num)
printf("tie\n");
else
printf("%s\n", party[can[0].id]);
return 0;
}