-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathant.c
44 lines (39 loc) · 1 KB
/
ant.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
#include <stdio.h>
#include <stdlib.h>
int get_max(int, int);
int main(){
int count, length;
scanf("%d%d", &count, &length);
int result = get_max(count, length);
printf("%d", result);
return 0;
}
int get_max(int count, int length){
int max = 0;
char * orientation = (char *) malloc(count * sizeof(char));
int * distance = (int *) malloc(count * sizeof(int));
for(int c = 0; c < count; c++){
scanf("%c", &orientation[c]);
if(orientation[c] != 'R' && orientation[c] != 'L'){
scanf("%c", &orientation[c]);
}
scanf("%d", &distance[c]);
}
for(int c = 0; c < count; c++){
switch(orientation[c]){
case 'R':
distance[c] = length - distance[c];
break;
case 'L':
break;
}
}
for(int c = 0; c < count; c++){
if(max <= distance[c]){
max = distance[c];
}
}
free(orientation);
free(distance);
return max;
}