-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzle.cpp
More file actions
59 lines (54 loc) · 1.49 KB
/
puzzle.cpp
File metadata and controls
59 lines (54 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
using namespace std;
int main()
{
cout<<"\n\n\n\t\t PUZZLE\n";
cout<<"\t\tversion 1.0\n\n\n";
int i,j,n=1,t,p,m,x,y;
int ara[3][3]={8,2,6,5,3,4,1,7,0};
for(i=0;i<3;i++){
cout<<"\t";
for(j=0;j<3;j++){
cout<<ara[i][j]<<" ";
if(ara[i][j]==0){
x=i;
y=j;
}
}
cout<<endl;
}
cout<<endl;
while(true){
//cout<<x<<' '<<y;
cout<<"\tinput number for replace : ";
cin>>p;
m=0;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(p==ara[i][j]){
if(ara[i][j+1]==0 || ara[i][j-1]==0 || ara[i+1][j]==0 || ara[i-1][j]==0){
ara[x][y]=p;
ara[i][j]=0;
x=i;
y=j;
m=1;
break;
}
else{
m=1;
cout<<"\n\n\tInvalid Move!!!\n\n";
break;
}
}
}
if(m==1) break;
}
for(i=0;i<3;i++){
cout<<"\t";
for(j=0;j<3;j++){
cout<<ara[i][j]<<" ";
}
cout<<endl;
}
}
}