# if语句满足了但是不执行是为什么,急急急急，明天就要交了

weixin_41581673 2018-01-03 05:24:22
//这是一个定义函数，我写的是6*6的五子棋
int victory()
{
int i,j,sum,sun;
sun=sum=0;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
if('o'==chess[i][j])
sun++;
else sun=0;
if(chess[i][j]=='+')
sum++;
else sum=0;
if(sun>=1)
{
printf("红方获胜");
b=1;
break;}
else if(sum>=5)
{
printf("蓝方获胜");
b=1;
break;}
}
}
...全文
1081 点赞 收藏 35

35 条回复

weixin_41581673 2018-01-08

wodexiaojidan 2018-01-04
``````#include <stdio.h>

char chess[][6] = {
' ', 'X', 'X', ' ', 'O', ' ',
' ', 'X', 'X', 'O', 'O', 'O',
' ', 'O', 'X', 'X', 'O', ' ',
' ', 'O', 'O', 'O', ' ', ' ',
' ', 'O', 'O', 'X', 'O', 'X',
' ', 'O', 'X', 'X', 'O', ' ',
};

int victory(void)
{
int row[6][6] = {0};		//横向连子数
int col[6][6] = {0};		//竖向连子数
int rlean[6][6] = {0};		//右斜连子数
int llean[6][6] = {0};		//左斜连子数

int i, j;
for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
row[i][j] = 1,
col[i][j] = 1,
rlean[i][j] = 1,
llean[i][j] = 1;
}
}

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
if(row[i][j] == 5 || col[i][j] == 5 || rlean[i][j] == 5 || llean[i][j] == 5){
if(chess[i][j] == 'X'){
printf("红方胜\n");

return 0;
}else if(chess[i][j] == 'O'){
printf("蓝方胜\n");

return 0;
}
}

if(j < 5 && chess[i][j] == chess[i][j + 1]){
row[i][j + 1] = row[i][j] + 1;
}

if(i < 5 && chess[i][j] == chess[i + 1][j]){
col[i + 1][j] = col[i][j] + 1;
}

if(i < 5 && j < 5 && chess[i][j] == chess[i + 1][j + 1]){
rlean[i + 1][j + 1] = rlean[i][j] + 1;
}

if(i < 5 && j > 1 && chess[i][j] == chess[i + 1][j - 1]){
llean[i + 1][j - 1] = llean[i][j] + 1;
}
}
}

printf("未分胜负,继续\n");

return -1;
}

int main(void)
{
victory();

return 0;
}``````

wodexiaojidan 2018-01-04

[quote=引用 24 楼 hzy_76 的回复:]

``````
if (cond)
{
...
}
``````

``````#include <stdio.h>

char chess[][6] = {
' ', 'X', 'X', ' ', 'O', ' ',
' ', 'X', 'X', 'O', 'O', ' ',
' ', 'O', 'X', 'X', 'O', ' ',
' ', 'O', 'O', 'O', 'X', ' ',
' ', 'O', 'X', 'X', 'O', 'X',
' ', 'O', 'X', 'X', 'O', ' ',
};

int victory(void)
{
int row[6][6] = {0};		//横向连子数
int col[6][6] = {0};		//竖向连子数
int rlean[6][6] = {0};		//右斜连子数
int llean[6][6] = {0};		//左斜连子数

int i, j;
for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
row[i][j] = 1,
col[i][j] = 1,
rlean[i][j] = 1,
llean[i][j] = 1;
}
}

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
if(row[i][j] == 5 || col[i][j] == 5 || rlean[i][j] == 5 || llean[i][j] == 5){
if(chess[i][j] == 'X'){
printf("红方胜\n");

return 0;
}else if(chess[i][j] == 'O'){
printf("蓝方胜\n");

return 0;
}
}

if(j < 5 && chess[i][j] == chess[i][j + 1]){
row[i][j + 1] = row[i][j] + 1;
}

if(i < 5 && chess[i][j] == chess[i + 1][j]){
col[i + 1][j] = col[i][j] + 1;
}

if(i < 5 && j < 5 && chess[i][j] == chess[i + 1][j + 1]){
rlean[i + 1][j + 1] = rlean[i][j] + 1;
}

if(i < 5 && j > 1 && chess[i][j] == chess[i + 1][j - 1]){
llean[i + 1][j - 1] = rlean[i][j] + 1;
}
}
}

printf("未分胜负,继续\n");

return -1;
}

int main(void)
{
victory();

return 0;
}``````

wodexiaojidan 2018-01-04

[quote=引用 21 楼 weixin_41581673 的回复:] 二维数组后面的.row什么的是什么
row是横排，col竖列，rlean右斜，llean左斜

``````#include <stdio.h>
#include <unistd.h>
#include <time.h>

int victory(void)
{
int row[6][6] = {0};		//横向连子数
int col[6][6] = {0};		//竖向连子数
int rlean[6][6] = {0};		//右斜连子数
int llean[6][6] = {0};		//左斜连子数

int i, j;
for(i = 0; i < 6; i++){
for(j = 0; j < 6; i++){
row[i][j] = 1,
col[i][j] = 1,
rlean[i][j] = 1,
llean[i][j] = 1;
}
}

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++){
if(row[i][j] == 5 || col[i][j] == 5 || rlean[i][j] == 5 || llean[i][j] == 5){
if(chess[i][j] == 'X'){
printf("红方胜\n");

return 0;
}else if(chess[i][j] == 'O'){
printf("蓝方胜\n");

return 0;
}
}

if(j < 5 && chess[i][j] == chess[i][j + 1]){
row[i][j + 1] = row[i][j] + 1;
}

if(i < 5 && chess[i][j] == chess[i + 1][j]){
col[i + 1][j] = col[i][j] + 1;
}

if(i < 5 && j < 5 && chess[i][j] == chess[i + 1][j + 1]){
rlean[i + 1][j + 1] = rlean[i][j] + 1;
}

if(i < 5 && j > 1chess[i][j] == chess[i + 1][j - 1]){
llean[i + 1][j - 1] = rlean[i][j] + 1;
}
}
}

printf("未分胜负,继续\n");

return -1;
}``````

weixin_41581673 2018-01-04

``````
if (cond)
{
...
}
``````

wodexiaojidan 2018-01-04

[quote=引用 21 楼 weixin_41581673 的回复:] 二维数组后面的.row什么的是什么
row是横排，col竖列，rlean右斜，llean左斜

weixin_41581673 2018-01-04

row是横排，col竖列，rlean右斜，llean左斜

wodexiaojidan 2018-01-04

row是横排，col竖列，rlean右斜，llean左斜

Acuity. 2018-01-04

weixin_41581673 2018-01-03

weixin_41581673 2018-01-03

row是横排，col竖列，rlean右斜，llean左斜

``````
if (cond)
{
...
}
``````

wojiaogaoyong123 2018-01-03

wodexiaojidan 2018-01-03

row是横排，col竖列，rlean右斜，llean左斜

weixin_41581673 2018-01-03

wodexiaojidan 2018-01-03
``````struct{
int        row;    	/* - */
int        col;    	/* | */
int        rlean; 	/* \ */
int  	   llean;	/* / */
char       color;
}chess[6][6];

int victory(void)
{
int i, j;

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++)
if(chess[i][j].row == 5 || chess[i][j].col == 5 || chess[i][j].rlean == 5 || chess[i][j].llean == 5){
if(chess[i][j].color == 'r'){
return;
}else if(chess[i][j].color == 'b'){
printf("Black Player is The Winner\n");
return;
}
}

if(chess[i][j].color == chess[i][(j + 1) % 6].color){
chess[i][(j + 1) % 6].row = chess[i][j].row + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][j].color){
chess[(i + 1) % 6][j].col = chess[i][j].col + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j + 1) % 6].rlean = chess[i][j].rlean + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j - 1 + 6) % 6].llean = chess[i][j].llean + 1;
}
}

printf("nobody wins the game\n");
}``````

wodexiaojidan 2018-01-03

``````struct{
int        row;    //	-
int        col;    //	|
int        rlean;  //	\
int		   llean   //	/
char       color;
}chess[6][6];

int victory(void)
{
int i, j;

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++)
if(chess[i][j].row == 5 || chess[i][j].col == 5 || chess[i][j].lean == 5){
if(chess[i][j].color == 'r'){
return;
}else if(chess[i][j].color == 'b'){
printf("Black Player is The Winner\n");
return;
}
}

if(chess[i][j].color == chess[i][(j + 1) % 6].color){
chess[i][(j + 1) % 6].row = chess[i][j].row + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][j].color){
chess[(i + 1) % 6][j].col = chess[i][j].col + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j + 1) % 6].rlean = chess[i][j].rlean + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j - 1 + 6) % 6].llean = chess[i][j].llean + 1;
}
}

printf("nobody wins the game\n");
}``````

wodexiaojidan 2018-01-03

weixin_41581673 2018-01-03

``````struct{
int		row;
int		col;
int		lean;
char	color;
}chess[6][6];

int victory(void)
{
int i, j;

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++)
if(chess[i][j].row == 5 || chess[i][j].col == 5 || chess[i][j].lean == 5){
if(chess[i][j].color == 'r'){
}else{
printf("Black Player Win");
}
}

if(chess[i][j].color == chess[i][(j + 1) % 6].color){
chess[i][(j + 1) % 6].row = chess[i][j].row + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][j].color){
chess[(i + 1) % 6][j].col = chess[i][j].col + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j + 1) % 6].lean = chess[i][j].lean + 1;
}
}
}``````

[/quote]尴尬，看不懂

wodexiaojidan 2018-01-03
``````struct{
int		row;
int		col;
int		lean;
char	color;
}chess[6][6];

int victory(void)
{
int i, j;

for(i = 0; i < 6; i++){
for(j = 0; j < 6; j++)
if(chess[i][j].row == 5 || chess[i][j].col == 5 || chess[i][j].lean == 5){
if(chess[i][j].color == 'r'){
}else{
printf("Black Player Win");
}
}

if(chess[i][j].color == chess[i][(j + 1) % 6].color){
chess[i][(j + 1) % 6].row = chess[i][j].row + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][j].color){
chess[(i + 1) % 6][j].col = chess[i][j].col + 1;
}

if(chess[i][j].color == chess[(i + 1) % 6][(j + 1) % 6].color){
chess[(i + 1) % 6][(j + 1) % 6].lean = chess[i][j].lean + 1;
}
}
}``````

C语言

6.4w+

C语言相关问题讨论

2018-01-03 05:24