50065. Move the Car
難度:2/5
\(t\)有可能不在\([0, 5]\)之間,但題目沒說。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#include <stdio.h>
#include "car.h"
CarStatusList carSimulation(CarStatus car, Command commands[]){
int i = 0;
CarStatusList s;
s.num = 0;
while(1){
int t = commands[i].t, v = commands[i].v;
if(t == 0 || t > 5) break;
else if(t == 1) car.g += v;
else{
if(car.g < v) break;
else{
if(t == 2) car.x += v;
if(t == 3) car.x -= v;
if(t == 4) car.y += v;
if(t == 5) car.y -= v;
car.g -= v;
s.status[s.num] = car;
s.num++;
}
}
i++;
}
return s;
}
50065. Move the Car
https://aaronlin1229.github.io/judgegirl_50065/