I got AC in http://www.programming-challenges.com/, but WA in UVA.
Or give me some critical i/o please.
Thanks in advance.
Code: Select all
/* ACM Problem Set */
/* Problem 10142 */
/* Australian Voting */
#include <cstdio>
#include <string.h>
using namespace std;
int main()
{
int t;
scanf("%d\n", &t);
scanf("\n");
for ( ; t > 0; t--)
{
char names[20][100];
bool skipped[20];
char votes[1000][20];
int cursors[1000];
memset (names, (char)0, sizeof(char) * 20 * 100);
memset (skipped, (bool)0, sizeof(bool) * 20);
memset (votes, (char)0, sizeof(char) * 20 * 1000);
memset (cursors, (char)0, sizeof(char) * 1000);
int count;
scanf("%d\n", &count);
for (int i = 0; i < count; i++) gets(names[i]);
int vote_count = -1;
char s[6000];
strcpy(s,"");
while (gets(s))
{
if (strlen(s) == 0) break;
vote_count++;
char s1[6000];
for (int i = 0; i < count; i++)
{
sscanf(s, "%d %6000c", &votes[vote_count][i], &s1);
strcpy(s, s1);
}
}
vote_count++;
int skip_count = 0;
while (skip_count < count)
{
//calculate votes
int votes_for_name[20];
memset (votes_for_name, (int)0, sizeof(int) * 20);
for (int i = 0; i < vote_count; i++)
votes_for_name[votes[i][cursors[i]]-1]++;
int min = vote_count, min_count = 0, max = 0;
for (int i = 0; i < count; i++)
{
if (skipped[i]) continue;
if (votes_for_name[i] < min)
{
min_count = 0;
min = votes_for_name[i];
}
if (votes_for_name[i] == min) min_count++;
}
//check for draw
if (min_count == (count - skip_count))
{
for (int i = 0; i < count; i++)
if (!skipped[i]) puts(names[i]);
break;
}
//skip ballots
for (int i = 0; i < count; i++)
if (votes_for_name[i] == min) skipped[i] = true;
//move cursors
for (int i = 0; i < vote_count; i++)
while (skipped[votes[i][cursors[i]]-1]) cursors[i]++;
skip_count += min_count;
}
if (t > 1) printf("\n");
}
}