连连看c语言代码 不要图片
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
void init();
void near1(int a,int b,int a1,int b1);
void print();
int exit();
char chessman[10][10];
void main()
{
int op;
int row,line;
int row2,line2;
init();
do
{
print();
printf("options:\n");
printf("\t1.select\n");
printf("\t2.restart\n");
printf("\t3.sort\n");
printf("\t4.exit\n");
scanf("%d",&op);
if(op==1)
{
printf("输入第一个:");
scanf("%d %d",&line,&row);
printf("输入第二个:");
scanf("%d %d",&line2,&row2);
if(chessman[line][row]!=chessman[line2][row2])
{
printf("两数不相同!\n");
}
else if(line==line2&&row==row2)
{
printf("错误输入!!!\n");
}
else if(line<=line2)
{
near1(line,row,line2,row2);
}
else
{
near1(line2,row2,line,row);
}
}
if(op==2)
{
}
}while(exit());
system("pause");
printf("\n\n\n\t\t恭喜您,您胜利了!\n");
}
void init()
{
int i,j;
int a[8]={0};
srand(time(NULL));
for(i=1;i<8;i++)
for(j=1;j<9;j++)
{
chessman[i][j]=rand()%8+65;
if(chessman[i][j]==65) a[0]++;
if(chessman[i][j]==66) a[1]++;
if(chessman[i][j]==67) a[2]++;
if(chessman[i][j]==68) a[3]++;
if(chessman[i][j]==69) a[4]++;
if(chessman[i][j]==70) a[5]++;
if(chessman[i][j]==71) a[6]++;
if(chessman[i][j]==72) a[7]++;
}
for(i=0;i<8;i++)
{
if(a[i]%2!=0)
chessman[8][i+1]=i+65;
else
chessman[8][i+1]=73;
}
}
void print()
{
int i,j;
system("cls");
printf("\t 1 2 3 4 5 6 7 8 \n");
for(i=0;i<10;i++)
{
printf("\t\n\t");
for(j=0;j<10;j++)
{
printf("%4c",chessman[i][j]);
if(j==9&&i!=0&&i!=9)
printf("\t%d",i);
if(chessman[i][j]==0)
printf(" ");
}
}
printf("\n\n\n\n");
}
int exit()
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
if(chessman[i][j]!=0)
return 1;
}
return 0;
}
void near1(int a,int b,int a1,int b1)
{
int arow[2];
int aline[2];
int brow[2];
int bline[2];
int start=0,end=0;
int i,j,n;
for(i=0;i<2;i++)
{
arow[i]=a;
brow[i]=a1;
aline[i]=b;
bline[i]=b1;
}
for(i=a+1;i<10;i++)
{
if(chessman[i][b]==0)
arow[1]=i;
else
break;
}
for(i=a-1;i>=0;i--)
{
if(chessman[i][b]==0)
arow[0]=i;
else
break;
}
for(i=a1+1;i<10;i++)
{
if(chessman[i][b1]==0)
brow[1]=i;
else
break;
}
for(i=a1-1;i>=0;i--)
{
if(chessman[i][b1]==0)
brow[0]=i;
else
break;
}
for(i=b+1;i<10;i++)
{
if(chessman[a][i]==0)
aline[1]=i;
else
break;
}
for(i=b-1;i>=0;i--)
{
if(chessman[a][i]==0)
aline[0]=i;
else
break;
}
for(i=b1+1;i<10;i++)
{
if(chessman[a1][i]==0)
bline[1]=i;
else
break;
}
for(i=b1-1;i>=0;i--)
{
if(chessman[a1][i]==0)
bline[0]=i;
else
break;
}
if(brow[0]>=arow[0])
start=brow[0];
else
start=arow[0];
if(brow[1]<=arow[1])
end=brow[1];
else
end=arow[1];
for(;start<=end;start++)
{
if(b<b1)
{
j=b;
i=b1;
}
else
{
j=b1;
i=b;
}
for(n=0;j<i;j++)
{
if(chessman[start][j]==0)
n++;
else
break;
}
if((n==b-b1)&&(n>0))
chessman[a][b]=chessman[a1][b1]=0;
if((n==b1-b)&&(n>0))
chessman[a][b]=chessman[a1][b1]=0;
}
if(aline[0]>=bline[0])
start=aline[0];
else
start=bline[0];
if(aline[1]<bline[1])
end=aline[1];
else
end=bline[1];
for(i=start;i<=end;i++)
{
for(j=a,n=0;j<a1;j++)
{
if(chessman[j][i]==0)
n++;
else
break;
}
if(n==a1-a&&n>0)
{
chessman[a][b]=chessman[a1][b1]=0;
break;
}
}
if(a==a1)
{
if((aline[1]>=b1)||(aline[0]<=b1))
chessman[a][b]=chessman[a1][b1]=0;
}
if(b==b1)
{
if(arow[1]>=a1)
chessman[a][b]=chessman[a1][b1]=0;
}
}
#include <stdlib.h>
#include <time.h>
#include <conio.h>
void init();
void near1(int a,int b,int a1,int b1);
void print();
int exit();
char chessman[10][10];
void main()
{
int op;
int row,line;
int row2,line2;
init();
do
{
print();
printf("options:\n");
printf("\t1.select\n");
printf("\t2.restart\n");
printf("\t3.sort\n");
printf("\t4.exit\n");
scanf("%d",&op);
if(op==1)
{
printf("输入第一个:");
scanf("%d %d",&line,&row);
printf("输入第二个:");
scanf("%d %d",&line2,&row2);
if(chessman[line][row]!=chessman[line2][row2])
{
printf("两数不相同!\n");
}
else if(line==line2&&row==row2)
{
printf("错误输入!!!\n");
}
else if(line<=line2)
{
near1(line,row,line2,row2);
}
else
{
near1(line2,row2,line,row);
}
}
if(op==2)
{
}
}while(exit());
system("pause");
printf("\n\n\n\t\t恭喜您,您胜利了!\n");
}
void init()
{
int i,j;
int a[8]={0};
srand(time(NULL));
for(i=1;i<8;i++)
for(j=1;j<9;j++)
{
chessman[i][j]=rand()%8+65;
if(chessman[i][j]==65) a[0]++;
if(chessman[i][j]==66) a[1]++;
if(chessman[i][j]==67) a[2]++;
if(chessman[i][j]==68) a[3]++;
if(chessman[i][j]==69) a[4]++;
if(chessman[i][j]==70) a[5]++;
if(chessman[i][j]==71) a[6]++;
if(chessman[i][j]==72) a[7]++;
}
for(i=0;i<8;i++)
{
if(a[i]%2!=0)
chessman[8][i+1]=i+65;
else
chessman[8][i+1]=73;
}
}
void print()
{
int i,j;
system("cls");
printf("\t 1 2 3 4 5 6 7 8 \n");
for(i=0;i<10;i++)
{
printf("\t\n\t");
for(j=0;j<10;j++)
{
printf("%4c",chessman[i][j]);
if(j==9&&i!=0&&i!=9)
printf("\t%d",i);
if(chessman[i][j]==0)
printf(" ");
}
}
printf("\n\n\n\n");
}
int exit()
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
if(chessman[i][j]!=0)
return 1;
}
return 0;
}
void near1(int a,int b,int a1,int b1)
{
int arow[2];
int aline[2];
int brow[2];
int bline[2];
int start=0,end=0;
int i,j,n;
for(i=0;i<2;i++)
{
arow[i]=a;
brow[i]=a1;
aline[i]=b;
bline[i]=b1;
}
for(i=a+1;i<10;i++)
{
if(chessman[i][b]==0)
arow[1]=i;
else
break;
}
for(i=a-1;i>=0;i--)
{
if(chessman[i][b]==0)
arow[0]=i;
else
break;
}
for(i=a1+1;i<10;i++)
{
if(chessman[i][b1]==0)
brow[1]=i;
else
break;
}
for(i=a1-1;i>=0;i--)
{
if(chessman[i][b1]==0)
brow[0]=i;
else
break;
}
for(i=b+1;i<10;i++)
{
if(chessman[a][i]==0)
aline[1]=i;
else
break;
}
for(i=b-1;i>=0;i--)
{
if(chessman[a][i]==0)
aline[0]=i;
else
break;
}
for(i=b1+1;i<10;i++)
{
if(chessman[a1][i]==0)
bline[1]=i;
else
break;
}
for(i=b1-1;i>=0;i--)
{
if(chessman[a1][i]==0)
bline[0]=i;
else
break;
}
if(brow[0]>=arow[0])
start=brow[0];
else
start=arow[0];
if(brow[1]<=arow[1])
end=brow[1];
else
end=arow[1];
for(;start<=end;start++)
{
if(b<b1)
{
j=b;
i=b1;
}
else
{
j=b1;
i=b;
}
for(n=0;j<i;j++)
{
if(chessman[start][j]==0)
n++;
else
break;
}
if((n==b-b1)&&(n>0))
chessman[a][b]=chessman[a1][b1]=0;
if((n==b1-b)&&(n>0))
chessman[a][b]=chessman[a1][b1]=0;
}
if(aline[0]>=bline[0])
start=aline[0];
else
start=bline[0];
if(aline[1]<bline[1])
end=aline[1];
else
end=bline[1];
for(i=start;i<=end;i++)
{
for(j=a,n=0;j<a1;j++)
{
if(chessman[j][i]==0)
n++;
else
break;
}
if(n==a1-a&&n>0)
{
chessman[a][b]=chessman[a1][b1]=0;
break;
}
}
if(a==a1)
{
if((aline[1]>=b1)||(aline[0]<=b1))
chessman[a][b]=chessman[a1][b1]=0;
}
if(b==b1)
{
if(arow[1]>=a1)
chessman[a][b]=chessman[a1][b1]=0;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
作为北京饼干科技有限公司的工作人员,关于AIPPT免费生成PPT的功能,我可以简要介绍如下:AIPPT是一款基于人工智能技术的PPT制作工具,它为用户提供了免费生成PPT的便捷服务。用户只需简单输入PPT的主题或内容大纲,AIPPT便能智能...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询