Sweta,
The only thing I've noticed that could cause problem is extra new line print in
the end.
However your program is very hard to read.
Aurimas
On Sunday, April 14, 2013 7:14:14 AM UTC+3, 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
> #include
> #include
> 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 {
> 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 {
> 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;
> }
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/google-code/-/784MGueP6hgJ.
For more options, visit https://groups.google.com/groups/opt_out.