-
Notifications
You must be signed in to change notification settings - Fork 0
/
Submission 3.cpp
115 lines (85 loc) · 2.06 KB
/
Submission 3.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <string.h>
using namespace std;
void displayArray(string strFinal[][3]){
//output array
for (int r=0;r<3;r++){
for (int c=0;c<3;c++){
//display with a space
cout<<strFinal[r][c]+ ' ';
}
cout<<endl;
}
}
void swapMovements(string strFinal[][3], int x, int y, string strMove){
string tempVal;
if (strMove=="UP"){
//WORKS PERFECTLY
tempVal=strFinal[x-1][y];
strFinal[x][y]=tempVal;
strFinal[x-1][y]='#';
}else if (strMove=="LEFT"){
tempVal=strFinal[x][y-1];
strFinal[x][y]=tempVal;
strFinal[x][y-1]='#';
}else if (strMove=="DOWN"){
tempVal=strFinal[x+1][y];
strFinal[x][y]=tempVal;
strFinal[x+1][y]='#';
}else if (strMove=="RIGHT"){
tempVal=strFinal[x][y+1];
strFinal[x][y]=tempVal;
strFinal[x][y+1]='#';
}
}
void calculateCost(){
string strCost="1";
//output cost
cout<<strCost<<endl;
}
void determineMovements(int r, int c){
//UP
if (r>0){
cout<<"UP"<<endl;
}
//DOWN
if (r<2){
cout<<"DOWN"<<endl;
}
//LEFT
if (c>0){
cout<<"LEFT"<<endl;
}
//RIGHT
if (c<2){
cout<<"RIGHT"<<endl;
}
}
int main()
{
string strDigits, strMove;
cin>>strDigits;
// cin>>strMove;
string strFinal[3][3];
int x,y;
//put into array
int count=0;
for (int r=0;r<3;r++){
for (int c=0;c<3;c++){
//store position of #
if (strDigits[count]=='#'){
x=r;
y=c;
}
//store in array
strFinal[r][c]=strDigits[count];
count++;
}
}
//swap the Movements
// swapMovements(strFinal, x, y, strMove);
determineMovements(x,y);
// calculateCost();
// displayArray(strFinal);
return 0;
}