Submission #1610241


Source Code Expand

#include <stdio.h>

struct tagCOUNTER {
	int count;
	char name[52];
} candidates[50] = {0};

int vote(char *const name)
{
	int i;
	int count=0;
	
	for(i=0;i<50;++i){
		char *dest = candidates[i].name;
		char *src = name;
		if(candidates[i].count < 1){
			++candidates[i].count;
			while('a'<=*src&&*src<='z'){
				*dest++=*src++;
			}
			*dest=*src='\0';
			count=candidates[i].count;
			break;
		} else {
			int diff=0;
			while('a'<=*src&&*src<='z'){
				diff += ((*dest++)!=(*src++));
			}
			*src='\0';
			diff += ((*dest)!=(*src));
			if(diff==0){
				++candidates[i].count;
				count=candidates[i].count;
				break;
			}
		}
	}
	return count;
}

int main(void)
{
	int n;
	char name[2][100]={0};
	int max = 0;
	int wp = 0;
	
	fgets(name[0],sizeof(name[0]),stdin);
	sscanf(name[0], "%d", &n);
	while(n-->0){
		int cnt;
		fgets(name[wp],sizeof(name[0]),stdin);
		cnt = vote(name[wp]);
		if(cnt > max){
			max = cnt;
			wp = (wp+1)%2;
		}
	}
	
	wp = (wp+1)%2;
	printf("%s\n", name[wp]);
	return 0;
}

Submission Info

Submission Time
Task B - 投票
User iseekautos
Language C (GCC 5.4.1)
Score 100
Code Size 1065 Byte
Status AC
Exec Time 1 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:48:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(name[0],sizeof(name[0]),stdin);
  ^
./Main.c:52:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(name[wp],sizeof(name[0]),stdin);
   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt
Case Name Status Exec Time Memory
case_01.txt AC 1 ms 128 KB
case_02.txt AC 1 ms 128 KB
case_03.txt AC 1 ms 128 KB
case_04.txt AC 1 ms 128 KB
case_05.txt AC 1 ms 128 KB
case_06.txt AC 1 ms 128 KB
case_07.txt AC 1 ms 128 KB
case_08.txt AC 1 ms 128 KB
case_09.txt AC 1 ms 128 KB
case_10.txt AC 1 ms 128 KB
case_11.txt AC 1 ms 128 KB
case_12.txt AC 1 ms 128 KB
case_13.txt AC 1 ms 128 KB
case_14.txt AC 1 ms 128 KB
case_15.txt AC 1 ms 128 KB
sample_01.txt AC 1 ms 128 KB
sample_02.txt AC 1 ms 128 KB
sample_03.txt AC 1 ms 128 KB