-
Notifications
You must be signed in to change notification settings - Fork 0
/
bike.cpp
56 lines (53 loc) · 1.84 KB
/
bike.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
#include <stdio.h>
void getNextDirection(int predX, int predY, int x, int y, char *nextDirection);
void getNextDirection(int predX, int predY, int x, int y, char *nextDirection){
if(x != predX){
if(x - predX > 0){
*nextDirection = 'A';
} else {
*nextDirection = 'C';
}
} else {
if(y - predY > 0){
*nextDirection = 'B';
} else {
*nextDirection = 'D';
}
}
}
void countDangerousCurves(char actualDirection, char nextDirection, int *countDangerousCurves);
void countDangerousCurves(char actualDirection, char nextDirection, int *countDangerousCurves){
if(actualDirection == 'A' && nextDirection == 'B'){
*countDangerousCurves = *countDangerousCurves + 1;
} else{
if(actualDirection == 'B' && nextDirection == 'C'){
*countDangerousCurves = *countDangerousCurves + 1;
} else {
if(actualDirection == 'C' && nextDirection == 'D'){
*countDangerousCurves = *countDangerousCurves + 1;
} else {
if(actualDirection == 'D' && nextDirection == 'A'){
*countDangerousCurves = *countDangerousCurves + 1;
}
}
}
}
}
int main(){
int n;
int xo, yo, predX, predY, x, y;
int dangerousCurves = 0;
char actualDirection = 'B';
char nextDirection;
scanf("%d %d %d %d %d %d %d", &n, &xo, &yo, &predX, &predY, &x, &y);
while(xo != x || yo != y){
getNextDirection(predX, predY, x, y, &nextDirection);
countDangerousCurves(actualDirection, nextDirection, &dangerousCurves);
actualDirection = nextDirection;
predX = x;
predY = y;
scanf("%d %d", &x, &y);
}
printf("%d", dangerousCurves);
return 0;
}