Help needed for UCL(Practice code)

I am a beginner and started with UCL as my first problem on code chef.My output is same as the expected output but when i submit my code it show’s that my answer is wrong.Please have a look at my code and help me(As i am a beginner i could not think of a better logic).
Link to the problem statement
#include<stdio.h>
#include<string.h>
int main()
{
int m;
scanf("%d",&m);
while(m–)
{
int a,b,i,j,k,l,temp,temp1;
char str1[10],str2[10];
char s1[10]="\0",s2[10]="\0",s3[10]="\0",s4[10]="\0";
char null[2]="\0";
static int g[4],p[4];
g[0]=g[1]=g[2]=g[3]=0;
p[0]=p[1]=p[2]=p[3]=0;
scanf("%s %d vs. %d %s",str1,&a,&b,str2);
strcpy(s1,str1);
strcpy(s2,str2);
for(i=1;i<=12;i++)
{
if(i>1)
{
scanf("%s %d vs. %d %s",str1,&a,&b,str2);
if(strcmp(null,s3)==0)
{
if(strcmp(s1,str1)!=0&&strcmp(s2,str1)!=0)
{
strcpy(s3,str1);
}
else if(strcmp(s1,str2)!=0&&strcmp(s2,str2)!=0)
{
strcpy(s3,str2);
}
}
if(strcmp(null,s4)==0)
{
if(strcmp(str1,s1)!=0&&strcmp(str1,s2)!=0&&strcmp(s3,str1)!=0)
{
strcpy(s4,str1);
}
else if(strcmp(str2,s1)!=0&&strcmp(str2,s2)!=0&&strcmp(str2,s3)!=0)
{
strcpy(s4,str2);
}
}
}
if(a>b)
{
if(strcmp(s1,str1)==0)
{
p[0]=p[0]+3;
g[0]=g[0]+(a-b);

    }
    if(strcmp(s2,str1)==0)
    {
        p[1]=p[1]+3;
        g[1]=g[1]+(a-b);
    }
    if(strcmp(s3,str1)==0)
    {
        p[2]=p[2]+3;
        g[2]=g[2]+(a-b);
    }
    if(strcmp(s4,str1)==0)
    {
        p[3]=p[3]+3;
        g[3]=g[3]+(a-b);
    }
    if(strcmp(s1,str2)==0)
    {
        g[0]=g[0]+(b-a);

    }
    if(strcmp(s2,str2)==0)
    {
        g[1]=g[1]+(b-a);
    }
    if(strcmp(s3,str2)==0)
    {
        g[2]=g[2]+(b-a);
    }
    if(strcmp(s4,str2)==0)
    {
        g[3]=g[3]+(b-a);
    }
}
if(a==b)
{
    if(strcmp(s1,str1)==0)
    {
        p[0]=p[0]+1;
    }
    if(strcmp(s2,str1)==0)
    {
        p[1]=p[1]+1;
    }
    if(strcmp(s3,str1)==0)
    {
        p[2]=p[2]+1;
    }
    if(strcmp(s4,str1)==0)
    {
        p[3]=p[3]+1;
    }
    if(strcmp(s1,str2)==0)
    {
        p[0]=p[0]+1;
    }
    if(strcmp(s2,str2)==0)
    {
        p[1]=p[1]+1;
    }
    if(strcmp(s3,str2)==0)
    {
        p[2]=p[2]+1;
    }
    if(strcmp(s4,str2)==0)
    {
        p[3]=p[3]+1;
    }

}
if(a<b)
{
    if(strcmp(s1,str2)==0)
    {
        p[0]=p[0]+3;
        g[0]=g[0]+(b-a);

    }
    if(strcmp(s2,str2)==0)
    {
        p[1]=p[1]+3;
        g[1]=g[1]+(b-a);
    }
    if(strcmp(s3,str2)==0)
    {
        p[2]=p[2]+3;
        g[2]=g[2]+(b-a);
    }
    if(strcmp(s4,str2)==0)
    {
        p[3]=p[3]+3;
        g[3]=g[3]+(b-a);
    }
    if(strcmp(s1,str1)==0)
    {
        g[0]=g[0]+(a-b);

    }
    if(strcmp(s2,str1)==0)
    {
        g[1]=g[1]+(a-b);
    }
    if(strcmp(s3,str1)==0)
    {
        g[2]=g[2]+(a-b);
    }
    if(strcmp(s4,str1)==0)
    {
        g[3]=g[3]+(a-b);
    }
}

}
int arr[4]={p[0],p[1],p[2],p[3]};
int ar[4]={g[0],g[1],g[2],g[3]};
for(i=0;i<3;i++)
{
for(j=0;j<3-i;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3-i;j++)
{
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
}
}
if(arr[3]==p[0])
{
if(ar[3]==g[0])
{
printf("%s “,s1);
}
}
if(arr[3]==p[1])
{
if(ar[3]==g[1])
{
printf(”%s “,s2);
}
}
if(arr[3]==p[2])
{
if(ar[3]==g[2])
{
printf(”%s “,s3);
}
}
if(arr[3]==p[3])
{
if(ar[3]==g[3])
{
printf(”%s “,s4);
}
}
if(arr[2]==p[0])
{
if(ar[2]==g[0])
{
printf(”%s “,s1);
}
}
if(arr[2]==p[1])
{
if(ar[2]==g[1])
{
printf(”%s “,s2);
}
}
if(arr[2]==p[2])
{
if(ar[2]==g[2])
{
printf(”%s “,s3);
}
}
if(arr[2]==p[3])
{
if(ar[2]==g[3])
{
printf(”%s ",s4);
}
}
}
}

I’d recommend, you should first check the problem’s editorial before asking here. If u are unable to understand it, we are always here to help.
You can find the editorial of any problem on the bottom of problem page.
Or click here

First of all…thank you for replying.I read the editorial but was unable to understand it’s explanation as I only know some basics of C but the solution is give in C++ and I am not able to understand the solutions given in C because of their complex logic.(please refer to the code once and tell me if there is a mistake I can rectify).

Congratulations for AC btw

That code on which I got AC is not written by me…I was just checking if it even gives a correct answer on a correct code …if I was happy with that I would not have asked for help here.

Hi I have submitted the following solution. But for some reason, the codechef has marked the answer as wrong. Can you please help in pointing out the flaw or the testcase where it failed might be helpful.
https://www.codechef.com/viewsolution/25331715

Hey I am also having the same problem. Can anyone here help me where I’m going wrong?
Link : https://www.codechef.com/viewsolution/25340020