87 lines
No EOL
2.1 KiB
C
87 lines
No EOL
2.1 KiB
C
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
|
|
char input[] =
|
|
{
|
|
#embed "input.txt"
|
|
,'\0' // null terminator
|
|
};
|
|
|
|
//char input[] = "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82\n";
|
|
int width = 0;
|
|
int height = 0;
|
|
int result = 0;
|
|
|
|
int parseNum(char* str){
|
|
int i = 0;
|
|
int out = 0;
|
|
while(str[i] != '\n'){
|
|
out += str[i]-0x30;
|
|
out *= 10;
|
|
i++;
|
|
}
|
|
out /=10;
|
|
return out;
|
|
}
|
|
|
|
int main(int argc, char *argv[]){
|
|
clock_t start, end;
|
|
start = clock();
|
|
|
|
int i = 0;
|
|
int num;
|
|
int position = 50;
|
|
int old_pos = 50;
|
|
while(input[i] != 0){
|
|
//printf("\n\n%.10s\n\n", &input[i+1]);
|
|
//sscanf(&input[i+1], "%d\n*", &num);
|
|
|
|
num = parseNum(&input[i+1]);
|
|
if(input[i] == 'L'){
|
|
//result += (((position + 10000 - num)%100)-10000-((position + 10000 - num)-10000))/100;
|
|
if(position == 0){
|
|
result -=100;
|
|
}
|
|
position = (position - num);
|
|
old_pos = position;
|
|
position = (position+10000)%100;
|
|
result += position-old_pos;
|
|
if(position == 0){
|
|
result +=100;
|
|
}
|
|
}
|
|
else{
|
|
//result += (((position + num))-((position + num)%100))/100;
|
|
//position = (position + num)%100;
|
|
position = (position + num);
|
|
old_pos = position;
|
|
position = (position)%100;
|
|
result += old_pos-position;
|
|
}
|
|
//printf("%d, %d, %d\n", num, position, result);
|
|
//fflush(stdout);
|
|
if(num<10){
|
|
i += 3;
|
|
} else if(num<100){
|
|
i += 4;
|
|
} else if(num<1000){
|
|
i += 5;
|
|
}
|
|
}
|
|
|
|
end = clock();
|
|
printf("count: %d\n", result/100);
|
|
clock_t ticks_taken = end - start;
|
|
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
|
|
printf("time take: %f ticks\n", time_taken);
|
|
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
|
|
|
|
|
|
exit(1);
|
|
} |