Fixed Day 4. Still looks very adventurous.
This commit is contained in:
parent
706036e2f3
commit
f4eb982e72
53
4/tuer4.c
53
4/tuer4.c
@ -1,61 +1,56 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
int numarr_to_int(char numarr[2], int tpos) {
|
||||||
int numarr_to_int(char numarr[2]) {
|
//printf("- D: %i; %i -\n", numarr[0]-'0', numarr[1]-'0'); //DEBUG
|
||||||
return (( (numarr[1] - '0') * 10 ) + (numarr[0] - '0'));
|
if(tpos==0) { return (numarr[1] - '0'); }
|
||||||
|
else { return (( (numarr[1] - '0') * 10 ) + (numarr[0] - '0')); }
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
void clear_num_arr(char numarr[2]) {
|
||||||
|
numarr[0] = '0'; numarr[1] = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { //Hi. The input-file has to have an empty line at the end. Sorry.
|
||||||
FILE *input_file = fopen("./input.txt", "r");;
|
FILE *input_file = fopen("./input.txt", "r");;
|
||||||
fseek(input_file, 0, SEEK_END);
|
fseek(input_file, 0, SEEK_END);
|
||||||
int if_size = ftell(input_file);
|
int if_size = ftell(input_file);
|
||||||
fseek(input_file, 0, SEEK_SET);
|
fseek(input_file, 0, SEEK_SET);
|
||||||
|
|
||||||
char input[if_size];
|
char input[if_size];
|
||||||
char c[1];
|
char c[1];
|
||||||
|
|
||||||
int val_arr[4];
|
int val_arr[4];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
char tmp_num[2];
|
char tmp_num[2];
|
||||||
int tmp_pos = 0;
|
int tmp_pos = 1;
|
||||||
|
|
||||||
int fully = 0;
|
int fully = 0;
|
||||||
|
int at_all = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
c[0] = fgetc(input_file);
|
c[0] = fgetc(input_file);
|
||||||
if((c[0] == (char)-1)) break;
|
|
||||||
|
|
||||||
if(c[0] == '-') {
|
if(c[0]=='-' || c[0]==',') {
|
||||||
tmp_pos = 0;
|
val_arr[pos] = numarr_to_int(tmp_num, tmp_pos);
|
||||||
val_arr[pos] = numarr_to_int(tmp_num);
|
tmp_pos = 1;
|
||||||
//printf("%i; %i; %i; %i\r\n", val_arr[0],val_arr[1],val_arr[2],val_arr[3]);
|
clear_num_arr(tmp_num);
|
||||||
pos++;
|
pos++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(c[0] == ',') {
|
if(c[0]=='\n' || c[0]=='\r') {
|
||||||
tmp_pos = 0;
|
val_arr[pos] = numarr_to_int(tmp_num, tmp_pos);
|
||||||
val_arr[pos] = numarr_to_int(tmp_num);
|
tmp_pos = 1;
|
||||||
pos++;
|
clear_num_arr(tmp_num);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(c[0] == '\n') {
|
|
||||||
tmp_pos = 0;
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
//printf("%i; %i; %i; %i\r\n", val_arr[0], val_arr[1], val_arr[2], val_arr[3]); //DEBUG
|
||||||
printf("%i; %i; %i; %i\r\n", val_arr[0],val_arr[1],val_arr[2],val_arr[3]);
|
if((val_arr[0]>=val_arr[2] && val_arr[1]<=val_arr[3]) || (val_arr[2]>=val_arr[0] && val_arr[3]<=val_arr[1])) fully++;
|
||||||
if(val_arr[0]<val_arr[1] && val_arr[2]>val_arr[3]) fully++;
|
if((val_arr[1]>=val_arr[2] && val_arr[0]<=val_arr[3]) || (val_arr[3]>=val_arr[0] && val_arr[2]<=val_arr[1])) at_all++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_num[tmp_pos] = c[0];
|
tmp_num[tmp_pos] = c[0];
|
||||||
tmp_pos++;
|
tmp_pos--;
|
||||||
}
|
}
|
||||||
while(c[0] != (char)-1);
|
while(c[0] != (char)-1);
|
||||||
|
|
||||||
|
|
||||||
printf("~UwU Twying c todayw, awwen't we master? *^w^* Hewe is youww wesult: UmU~ : %i\r\n", fully);
|
printf("~UwU Twying c todayw, awwen't we master? *^w^* Hewe is youww wesult: UmU~ : %i\r\n", fully);
|
||||||
|
printf("!OwO WHat wAs thAt MAstaww?!?! You wouwd like additioneww infowmatiown?!: UmU~ : %i\r\n", at_all);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user