✨ Two new stars! Written in C!
This commit is contained in:
parent
b1b12399fc
commit
1d4ec295f7
1000
2020/2/input
Normal file
1000
2020/2/input
Normal file
File diff suppressed because it is too large
Load Diff
BIN
2020/2/parse
Executable file
BIN
2020/2/parse
Executable file
Binary file not shown.
32
2020/2/parse.c
Normal file
32
2020/2/parse.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
int valid = 0;
|
||||
|
||||
fp = fopen("input", "r");
|
||||
|
||||
while(getline(&line, &len, fp) != -1) {
|
||||
int start, end;
|
||||
char subject;
|
||||
char* password;
|
||||
|
||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||
|
||||
|
||||
int occ = 0;
|
||||
for(int i=0; password[i] != 0; i++) {
|
||||
if(password[i] == subject) occ++;
|
||||
}
|
||||
|
||||
if(occ <= end && occ >= start) valid++;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
printf("There are %d valid passwords\n", valid);
|
||||
}
|
BIN
2020/2/parse_idk_two
Executable file
BIN
2020/2/parse_idk_two
Executable file
Binary file not shown.
27
2020/2/parse_idk_two.c
Normal file
27
2020/2/parse_idk_two.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
int valid = 0;
|
||||
|
||||
fp = fopen("input", "r");
|
||||
|
||||
while(getline(&line, &len, fp) != -1) {
|
||||
int start, end;
|
||||
char subject;
|
||||
char* password;
|
||||
|
||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||
|
||||
if(password[start - 1] == subject && password[end - 1] != subject ||
|
||||
password[end - 1] == subject && password[start - 1] != subject)
|
||||
valid++;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
printf("There are %d valid passwords\n", valid);
|
||||
}
|
Loading…
Reference in New Issue
Block a user