把数码问题就是把一串数字变成下面这个样?/p>
:
1
2
3
8
0
4
7
6
5
实现方法
1.
过程表示
源代码:
#include<stdio.h>
static int style[9]={1,2,3,6,7,4,5,8,0};//
输入的数?/p>
//2,5,4,3,0,7,1,8,6
3,2,1,8,0,4,7,6,5
1,0,4,2,7,3,8,5,6
1,0,3,8,2,4,7,6,5
static int arrayStep41[6]={5,4,3,6,7,8};//
第四步和第六步共用的数组,所以设为全局?/p>
static int arrayStep71[4]={3,6,7,4};
static int local;//
空格的位?/p>
int i,j;//
所用到的变?/p>
int number=0;//
记录移动步数
void print();
void step1();
void step2();
void step3();
void step4();
void step5();
void step6();
void step7();
void step8();
void step9();
void exchange(int x,int y);
void judge();
void judge()//
判断空格位置
{
number = 0;
for(i=0;i<9;i++)
{
if(style[i]==0)
{
local=i;
return;
}
}
}
void exchange(int x,int y)//
交换两个?/p>