Skip to content

Commit 563f4aa

Browse files
Create program.c
1 parent 0d93c92 commit 563f4aa

File tree

1 file changed

+53
-0
lines changed
  • programs/2016/C/01-No_Time_for_a_Taxicab

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// LIBRARIES:
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include <stdbool.h>
6+
7+
8+
int main() {
9+
10+
// --- MAIN VARIABLES:
11+
static bool debug_mode = false;
12+
int i;
13+
14+
// --- TEXT CONVERSION:
15+
// I convert the input file from raw text to usable list input.
16+
// This is mandatory for now, as I'm using an online IDE
17+
// (which doesn't allow to upload files in a workspace)...
18+
19+
char* rawInput = "L4, L3, R1, L4, R2, R2, L1, L2, R1, R1, L3, R5, L2, R5, L4, L3, R2, R2, L5, L1, R4, L1, R3, L3, R5, R2, L5, R2, R1, R1, L5, R1, L3, L2, L5, R4, R4, L2, L1, L1, R1, R1, L185, R4, L1, L1, R5, R1, L1, L3, L2, L1, R2, R2, R2, L1, L1, R4, R5, R53, L1, R1, R78, R3, R4, L1, R5, L1, L4, R3, R3, L3, L3, R191, R4, R1, L4, L1, R3, L1, L2, R3, R2, R4, R5, R5, L3, L5, R2, R3, L1, L1, L3, R1, R4, R1, R3, R4, R4, R4, R5, R2, L5, R1, R2, R5, L3, L4, R1, L5, R1, L4, L3, R5, R5, L3, L4, L4, R2, R2, L5, R3, R1, R2, R5, L5, L3, R4, L5, R5, L3, R1, L1, R4, R4, L3, R2, R5, R1, R2, L1, R4, R1, L3, L3, L5, R2, R5, L1, L4, R3, R3, L3, R2, L5, R1, R3, L3, R2, L1, R4, R3, L4, R5, L2, L2, R5, R1, R2, L4, L4, L5, R3, L4";
20+
size_t inputLength = strlen(rawInput);
21+
22+
if(debug_mode) {
23+
printf("\nSize = %zu\n", inputLength);
24+
printf("\nInput:\n\"%s\"", rawInput);
25+
}
26+
27+
// Transforming the raw input into proper data
28+
char* rawInputBuffer = malloc( sizeof(char) * (inputLength+1) );
29+
strcpy(rawInputBuffer, rawInput) ;
30+
31+
char** input = malloc( sizeof(char*) * inputLength ) ;
32+
static int loopCounter = 0 ;
33+
34+
35+
// Tokenizing the input here:
36+
char *inputToken = strtok(rawInput, ", ");
37+
38+
while( inputToken != NULL ) {
39+
input[loopCounter] = inputToken ;
40+
inputToken = strtok(NULL, ", ") ; // We keep tokenizing the same STRING, with the "NULL" variable.
41+
42+
loopCounter++ ;
43+
}
44+
45+
46+
47+
48+
49+
50+
return 0;
51+
52+
53+
}

0 commit comments

Comments
 (0)