On Sunday, 14 April 2013 09:44:14 UTC+5:30, sweta sharma  wrote:
> I wrote the following program . The program is giving correct output for 
> theinput file but the program isnt accepted...Its showing that its 
> Incorrect...Can someone please tell me what the problem is ? 
> 
> Source code :
> 
> #include<stdio.h>
> #include<ctype.h>
> #include<stdlib.h>
> struct p
> {
>   char board[4][4];
> }*arr;
> char check_horizontal(int i,int j,int *full)
> {
>    
> if(((arr[i].board[j][0]=='X')||(arr[i].board[j][0]=='T'))&&((arr[i].board[j][1]=='X')||(arr[i].board[j][1]=='T'))&&((arr[i].board[j][2]=='X')||(arr[i].board[j][2]=='T'))&&((arr[i].board[j][3]=='X')||(arr[i].board[j][3]=='T')))
>  
>   {
>     return 'X';
>   }
>    
> if(((arr[i].board[j][0]=='O')||(arr[i].board[j][0]=='T'))&&((arr[i].board[j][1]=='O')||(arr[i].board[j][1]=='T'))&&((arr[i].board[j][2]=='O')||(arr[i].board[j][2]=='T'))&&((arr[i].board[j][3]=='O')||(arr[i].board[j][3]=='T')))
>  
>     return 'O';
>   
> if((arr[i].board[j][0]=='.')||(arr[i].board[j][1]=='.')||(arr[i].board[j][2]=='.')||(arr[i].board[j][3]=='.'))
>     *full=0;
>    return 'N';
> } 
> char check_vertical(int i,int j)
> {
>    
> if(((arr[i].board[0][j]=='X')||(arr[i].board[0][j]=='T'))&&((arr[i].board[1][j]=='X')||(arr[i].board[1][j]=='T'))&&((arr[i].board[2][j]=='X')||(arr[i].board[2][j]=='T'))&&((arr[i].board[3][j]=='X')||(arr[i].board[3][j]=='T')))
>  
>     return 'X';
>    
> if(((arr[i].board[0][j]=='O')||(arr[i].board[0][j]=='T'))&&((arr[i].board[1][j]=='O')||(arr[i].board[1][j]=='T'))&&((arr[i].board[2][j]=='O')||(arr[i].board[2][j]=='T'))&&((arr[i].board[3][j]=='O')||(arr[i].board[3][j]=='T')))
>  
>    {
>     return 'O';
>   }
>     return 'N';
> } 
> char check_diagonal(int i,int j)
> {
>    if(j==0)
>    {
>      
> if(((arr[i].board[0][0]=='X')||(arr[i].board[0][0]=='T'))&&((arr[i].board[1][1]=='X')||(arr[i].board[1][1]=='T'))&&((arr[i].board[2][2]=='X')||(arr[i].board[2][2]=='T'))&&((arr[i].board[3][3]=='X')||(arr[i].board[3][3]=='T')))
>  
>     return 'X';
>    
> if(((arr[i].board[0][0]=='O')||(arr[i].board[0][0]=='T'))&&((arr[i].board[1][1]=='O')||(arr[i].board[1][1]=='T'))&&((arr[i].board[2][2]=='O')||(arr[i].board[2][2]=='T'))&&((arr[i].board[3][3]=='O')||(arr[i].board[3][3]=='T')))
>  
>     return 'O';
>    } 
>    if(j==3)
>    {
>       
> if(((arr[i].board[0][3]=='X')||(arr[i].board[0][3]=='T'))&&((arr[i].board[1][2]=='X')||(arr[i].board[1][2]=='T'))&&((arr[i].board[2][1]=='X')||(arr[i].board[2][1]=='T'))&&((arr[i].board[3][0]=='X')||(arr[i].board[3][0]=='T')))
>  
>     return 'X';
>    
> if(((arr[i].board[0][3]=='O')||(arr[i].board[0][3]=='T'))&&((arr[i].board[1][2]=='O')||(arr[i].board[1][2]=='T'))&&((arr[i].board[2][1]=='O')||(arr[i].board[2][1]=='T'))&&((arr[i].board[3][0]=='O')||(arr[i].board[3][0]=='T')))
>  
>     return 'O';
>    } 
>    return 'N';
> }
> 
> int main()
> {
>   FILE *fp,*f;
>   fp=fopen("A-small-attempt0.in","r");
>   f=fopen("out.txt","w");
>   int n,i,j,k,draw,full=1;
>   char ch;
>   fscanf(fp,"%d\n",&n); 
>   arr=(struct p *)malloc(n*sizeof(struct p));
>   for(i=0;i<n;i++)
>   {
>     for(j=0;j<4;j++)
>     {
>            arr[i].board[j][0]=fgetc(fp);
>            arr[i].board[j][1]=fgetc(fp);
>            arr[i].board[j][2]=fgetc(fp);
>            arr[i].board[j][3]=fgetc(fp);
>            ch=fgetc(fp);
>         
>     }
>     ch=fgetc(fp);
>      
>   }
>   for(i=0;i<n;i++)
>   {
>     draw=1;full=1; 
>     for(j=0;j<4;j++)
>     {
>       ch=check_horizontal(i,j,&full);
>       if(ch=='X')
>       {
>          fprintf(f,"Case #%d: X won\n",i+1);
>          break;
>       }
>       else if(ch=='O')
>       {  
>          fprintf(f,"Case #%d: O won\n",i+1);
>          break;
>       }
>       if(ch=='N')
>       ch=check_vertical(i,j); 
>       if(ch=='X')
>       {
>          fprintf(f,"Case #%d: X won\n",i+1);
>          break;
>       }
>       else if(ch=='O')
>       {  
>          fprintf(f,"Case #%d: O won\n",i+1);
>          break;
>       }
>       if((j==0)||(j==3))
>       {
>          ch=check_diagonal(i,j);
>          if(ch=='X')
>       {
>          fprintf(f,"Case #%d: X won\n",i+1);
>          break;
>       }
>       else if(ch=='O')
>       {  
>          fprintf(f,"Case #%d: O won\n",i+1);
>          break;
>       }
>       }
>      }
>      if((ch=='N')&&(full==1))
>      {
>         fprintf(f,"Case #%d: Draw\n",i+1);
>      }
>      else if ((full==0)&&(ch=='N'))
>      {  
>         fprintf(f,"Case #%d: Game has not completed\n",i+1);
>      }
>    } 
>    fprintf(f,"\n"); 
>    fclose(fp);
>    fclose(f);
>    return 0;
> }


@arunimas .. even without the new line the program wasnt accepted and 
@tussarsingh13 : I tried hard to debug it but there doesnt seem any problem 
with the code...

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-code/-/bGARuRtvxscJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to