https://www.codechef.com/problems/FBMT
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
int main() {
int t, len;
int c1,c2,j;
char s1[21];
char s2[21];
char temp[21];
scanf("%d", &t);
while(!t)
{
c1=1;
c2=0;
scanf("%d",&len);
scanf("%s",&s1);
for(j=1;j<len;j++)
{
scanf("%s",&temp);
if((strcmp(s1,temp)==0))
c1++;
else
{
strcpy(s2,temp);
c2++;
}
}
if(c1 > c2)
printf("%s\n", s1);
else if(c2 > c1)
printf("%s\n", s2);
else
printf("Draw\n");
t--;
}
return 0;
}
Asked by: Ankan_Ghosh on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
Errors in your code:
1. while(!t) : if t>0 , while loop is never executed as while(!t) evaluates to false. Use while(t).
2. scan("%s",&s1): You don't need to use '&' while taking string input. (Same for temp)
Note: Instead of copying the value of temp in s2 again and again, try to do that once.