-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrone-control.c
167 lines (104 loc) · 3.09 KB
/
drone-control.c
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*A drone is floating in space. Its initial coordinates are (X,Y,Z). You send a series of C movement commands to the drone.There are 6 movement commands 1, 2, 3, 4, 5 and 6.
1--UP
For Example, if the drone is at (0,0,0), then after the command it will be at (0,0,1)
2--Down
For Example, if the drone is at (0,0,0), then after the command it will be at (0,0,-1)
3--North
For Example, if the drone is at (0,0,0), then after the command it will be at (1,0,0)
4--South
For Example, if the drone is at (0,0,0), then after the command it will be at (-1,0,0)
5--East
For Example, if the drone is at (0,0,0), then after the command it will be at (0,1,0)
6--West
For Example, if the drone is at (0,0,0), then after the command it will be at (0,-1,0)
Time Elapsed=0, just before the first command is issued.
Consider that each command takes 1 time unit to execute.
For Example, At Timestamp T=5 if the drone is at (1,5,3) and we issue the command 1(UP), then at Timestamp T=6 it will be at (1,5,4).
Given Q queries where each query is a timestamp t, you will have to output the coordinate of the drone at each of the timestamps.
To sum up:
(X,Y,Z) is the initial position of the drone.
C is the number of commands issued
Q is the number of queries
Input Format:
The first line contains 5 space separated integers X, Y, Z, C, Q.
The second line contains C space separated integers describing the commands. Each of these C commands can be 1, 2, 3, 4, 5 or 6.
The third line contains Q space separated integers specifying the queries. Each of these Q queries specifies a timestamp t at which the coordinate of the drone is required. 0 ? t ? C.
Output:
Print Q lines corresponding to each of the Q queries.
In each line print 3 space separated integers a,b,c . Where (a,b,c) is the coordinate of the drone at the given timestamp.
Constraints:
1 <= N <= 200
1 <= Q <= 200
Example Input:
0 0 0 3 3
1 1 4
0 3 2
Example Output:
0 0 0
-1 0 2
0 0 2
Explanation:
At Timestamp T=0, position of Drone: (0,0,0)
At Timestamp T=1, position of Drone: (0,0,1)
At Timestamp T=2, position of Drone: (0,0,2)
At Timestamp T=3, position of Drone: (-1,0,2)*/
// solution:
#include <stdio.h>
int main()
{
int X, Y, Z, C, Q;
int c;
int t;
scanf("%d", &X);
scanf("%d", &Y);
scanf("%d", &Z);
scanf("%d", &C);
scanf("%d", &Q);
int x[C + 2];
int y[C + 2];
int z[C + 2];
x[0] = X;
y[0] = Y;
z[0] = Z;
for (int i = 1; i <= C; i++)
{
scanf("%d", &c);
if (c == 1)
{
Z++;
}
else if (c == 2)
{
Z--;
}
else if (c == 3)
{
X++;
}
else if (c == 4)
{
X--;
}
else if (c == 5)
{
Y++;
}
else if (c == 6)
{
Y--;
}
x[i] = X;
y[i] = Y;
z[i] = Z;
}
for (int j = 1; j <= Q; j++)
{
scanf("%d", &t);
printf("%d %d %d", x[t], y[t], z[t]);
if (j < Q)
{
printf("\n");
}
}
return 0;
}