#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct team
{
char name[10];
int point;
int gs;
int gc;
int gd;
};
int main(void)
{
struct team t[4];
int testcase;
int i,j,k;
char t1[10],t2[10];
int first,second;
int gh, ga;
scanf("%d",&testcase);
int count=0;
for(int x=0;x<4;x++)
{
t[x].gs=0;
t[x].gc=0;
t[x].point=0;
}
for (i=0;i<testcase;i++)
{
for(j=0;j<12;j++)
{
scanf("%s %d vs. %d %s", t1, &gh, &ga, t2);
if(count!=4)
{
if(count==0)
{
strcpy(t[count].name,t1);
count++;
}
if(count==1)
{
strcpy(t[count].name,t2);
count++;
}
int jmp1=0;
int jmp2=0;
for(k=0;k<count;k++)
{
if(!strcmp(t[k].name,t1))
{
jmp1++;
}
if(!strcmp(t[k].name, t2))
{
jmp2++;
};
}
if(jmp1==0)
{
strcpy(t[count].name,t1);
count++;
}
if(jmp2==0)
{
strcpy(t[count].name,t2);
count++;
}
}
for(k=0;k<4;k++)
{
if(!strcmp(t[k].name,t1))
{
t[k].gs+=gh;
t[k].gc+=ga;
if(gh>ga)
{
t[k].point+=3;
}
else if(gh<ga)
{
t[k].point+=0;
}
else
{
t[k].point+=1;
}
}
if(!strcmp(t[k].name,t2))
{
t[k].gs+=ga;
t[k].gc+=gh;
if(gh>ga)
{
t[k].point+=0;
}
else if(gh<ga)
{
t[k].point+=3;
}
else
{
t[k].point+=1;
}
}
}
for(k=0;k<4;k++)
{
t[k].gd=t[k].gs-t[k].gc;
if(k==0)
{
first=0;
second=1;
}
else
{
if(t[k].point>t[first].point)
{
second=first;
first=k;
}
else if(t[k].point>t[second].point)
{
second=k;
}
}
}
for(k=0;k<4;k++)
{
if(k==first)
continue;
if(k==second)
continue;
if(t[k].point==t[first].point)
{
if(t[k].gd>t[first].gd)
{
second=first;
first=k;
}
}
else if(t[k].point==t[second].point)
{
if(t[k].gd>t[second].gd)
{
second=k;
}
}
}
}
}
printf("%s",t[first].name);
printf(" %s",t[second].name);
return 0;
}
Is there something wrong with the code? I tried it for 5-6 different input sections, it works fine. Thanks in advance.