Home > Back-end >  C if not learned pointer, this code can also simplify
C if not learned pointer, this code can also simplify

Time:01-24

 
# include & lt; Stdio. H>

Int main () {
Int x, y;
Int y [3] [3]={
,8,8 {8},
,8,8 {8},
,8,8 {8},
};
Int I=2;
Printf (" 1, 2, 3 \ n \ | | n1 % d % d % d \ n -- -- -- -- -- \ | | n2 % d % d % d \ n -- -- -- -- -- \ | | n3 % d % d % d \ n ", xy [0] [0], xy [0] [1], the xy [0], [2], the xy [1] [0], xy [1] [1], the xy [1] [2], the xy [2] [0], xy [2] [1], the xy [2] [2]).//discharge tic-tac-toe game
While (I==2) {
Const int SIZE=3;
Int t, j;
Int hz, hf, lz, lf, ZDJZ, ZDJF, FDJZ, FDJF;//define rows and columns, the diagonal sides counter variable
Hz=hf=lz=lf=ZDJZ=ZDJF=FDJZ=FDJF=0;//initialize a variable

//enter

Do {
Printf (" square, please input in eight areas: ");
The scanf (" % d, % d ", & amp; X, & amp; Y);
} while (x, y [1] x [1] y!=8 | | x> 3 | | x<1 | | y> 3 | | y<1);//check

Y [1] x [1] y=1;//1 to tetragonal
Printf (" 1, 2, 3 \ n \ | | n1 % d % d % d \ n -- -- -- -- -- \ | | n2 % d % d % d \ n -- -- -- -- -- \ | | n3 % d % d % d \ n ", xy [0] [0], xy [0] [1], the xy [0], [2], the xy [1] [0], xy [1] [1], the xy [1] [2], the xy [2] [0], xy [2] [1], the xy [2] [2]).//discharge tic-tac-toe game

//cycle judgment
For (t=0; tHz=lz=0;
for(j=0; j//check the line
If (x, y [t] [j]==1 & amp; & Y [t] [j]. {
=8)Hz++;
}
If (hz==3) {
i=1;
Goto out;
}
//check list
If (x, y [j] [t]==1 & amp; & Y [j] [t]! {
=8)Lz++;
}
If (lz==3) {
i=1;
Goto out;
}
}
//check is diagonal
If (x, y [t] [t]==1 & amp; & Y [t] [t]! {
=8)Zdjz++;
}
If (ZDJZ==3) {
i=1;
Goto out;
}
//check the diagonal
If (x, y [t] [] SIZE - t - 1==1 & amp; & Y [t] [SIZE - t - 1]. {
=8)Fdjz++;
}
If (FDJZ==3) {
i=1;
Goto out;
}
}
Hz://printf (" % d, lz: % d, ZDJZ: % d, FDJZ: % d \ n \ n ", hz, lz, ZDJZ, FDJZ);
Do {
Printf (" opposition, please input in eight areas: ");
The scanf (" % d, % d ", & amp; X, & amp; Y);
} while (x, y [1] x [1] y!=8 | | x> 3 | | x<1 | | y> 3 | | y<1);//check

Y [1] x [1] y=0;//0 for the anti-side
Printf (" 1, 2, 3 \ n \ | | n1 % d % d % d \ n -- -- -- -- -- \ | | n2 % d % d % d \ n -- -- -- -- -- \ | | n3 % d % d % d \ n ", xy [0] [0], xy [0] [1], the xy [0], [2], the xy [1] [0], xy [1] [1], the xy [1] [2], the xy [2] [0], xy [2] [1], the xy [2] [2]).//discharge tic-tac-toe game

//cycle judgment
For (t=0; tHf=lf=0;
for(j=0; j//check the line
If (x, y [t] [j]==0 & amp; & Y [t] [j]. {
=8)Hf++;
}
If (hf==3) {
I=0;
Goto out;
}
//check list
If (x, y [j] [t]==0 & amp; & Y [j] [t]! {
=8)Lf++;
}
If (lf==3) {
I=0;
Goto out;
}
}
//check is diagonal
If (x, y [t] [t]==0 & amp; & Y [t] [t]! {
=8)Zdjf++;
}
If (ZDJF==3) {
I=0;
Goto out;
}
//check the diagonal
If (x, y [t] [] SIZE - t - 1==0 & amp; & Y [t] [SIZE - t - 1]. {
=8)Fdjf++;
}
If (FDJF==3) {
I=0;
Goto out;
}
}
Hf://printf (" % d, lf: % d, ZDJF: % d, FDJF: % d \ n \ n ", hf, lf, ZDJF, FDJF);


}
Out:
If (I==1) {
Printf (" tetragonal victory ");
} else {
Printf (" opposition victory ");
}


return 0;
}




Learn WengKai introduction to the C language, now learned 6 weeks, the fourth quarter, two-dimensional arrays, here the tic-tac-toe game, I think I can write a in learned before, so I just wrote a, but I think the code should also to simplify the use I learn knowledge, but I don't know how to simplify the,,,

CodePudding user response:

There are repeated, nature can be simplified,

CodePudding user response:

This saying is on the process simplified, later can also examine the simplified algorithm,

CodePudding user response:

But don't know how to optimize the,,,,,,,
  • Related