1
+ #include < iostream>
2
+ #include < conio.h>
3
+
4
+ using namespace std ;
5
+
6
+ int pre;
7
+
8
+ void parking_exit (int parking_lot[3 ][5 ]);
9
+ void moving (int stair, int pos );
10
+ void floor (int x, int parking_lot[3 ][5 ]);
11
+ void takeInput (int parking_lot[][5 ]);
12
+ void Print (int parking_lot[][5 ]);
13
+
14
+ main ()
15
+ {
16
+ int parking_lot[3 ][5 ] = {{2 , 0 , 0 , 1 , 0 },
17
+ {1 , 0 , 0 , 0 , 0 },
18
+ {0 , 0 , 0 , 0 , 0 }};
19
+ takeInput ( parking_lot);
20
+ Print (parking_lot);
21
+ parking_exit (parking_lot);
22
+ }
23
+
24
+ void takeInput (int parking_lot[][5 ])
25
+ {
26
+ int a = 2 ;
27
+ for (int x = 0 ; x < 3 ; x++)
28
+ {
29
+ if ( x != 2 )
30
+ {
31
+ cout << " For Floor " << a << endl;
32
+ }
33
+ else {
34
+ cout << " For ground floor " <<endl;
35
+ }
36
+ for ( int y = 0 ; y < 5 ; y++)
37
+ {
38
+ cout << " Enter the " << y + 1 << " place value : " ;
39
+ cin >> parking_lot[x][y];
40
+ cout << endl;
41
+ }
42
+ a--;
43
+ }
44
+ }
45
+
46
+ void Print (int parking_lot[][5 ])
47
+ {
48
+ for ( int x = 0 ; x< 3 ; x ++)
49
+ {
50
+ for ( int y = 0 ; y < 5 ; y++)
51
+ {
52
+ cout << " \t " << parking_lot[x][y];
53
+ }
54
+ cout << endl;
55
+ }
56
+ }
57
+
58
+ void parking_exit (int parking_lot[3 ][5 ])
59
+ {
60
+ int pos;
61
+ floor (0 , parking_lot);
62
+ floor (1 , parking_lot);
63
+ if (pre != 4 )
64
+ {
65
+ cout << " Move Right : " << 4 - pre;
66
+ }
67
+ }
68
+
69
+ void floor (int x, int parking_lot[3 ][5 ])
70
+ {
71
+ int stair;
72
+ int position;
73
+ if (x == 1 )
74
+ {
75
+ position = pre;
76
+ }
77
+ for (int i = 0 ; i < 5 ; i++)
78
+ {
79
+ if (parking_lot[x][i] == 1 )
80
+ {
81
+
82
+ stair = i;
83
+ pre = i;
84
+ }
85
+ if (parking_lot[x][i] == 2 )
86
+ {
87
+
88
+ position = i;
89
+ }
90
+ }
91
+ moving (stair, position);
92
+ }
93
+
94
+ void moving (int stair, int pos)
95
+ {
96
+
97
+ if (pos > stair)
98
+ {
99
+ cout << " Move Left : " << pos - stair << endl;
100
+ }
101
+ else if (pos < stair)
102
+ {
103
+ cout << " Move Right : " << stair - pos << endl;
104
+ }
105
+
106
+ cout << " Move Down : 1" << endl;
107
+ }
0 commit comments