diff options
| author | Mistivia <i@mistivia.com> | 2024-01-27 14:28:51 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-01-27 14:28:51 +0800 |
| commit | 087a111b3417cbda03a3453b3d16dd4d1cf54a9e (patch) | |
| tree | 000a15054865c3fb974970238568bb1d81a3f29e /advent-of-code/2022/06/2.c | |
| parent | 203658f4a5b8649d0142ab8ff6440eb0eefa48e9 (diff) | |
add aoc 2022
Diffstat (limited to 'advent-of-code/2022/06/2.c')
| -rw-r--r-- | advent-of-code/2022/06/2.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/advent-of-code/2022/06/2.c b/advent-of-code/2022/06/2.c new file mode 100644 index 0000000..4cf030c --- /dev/null +++ b/advent-of-code/2022/06/2.c @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <stdbool.h> + +bool succ(char *buf) { + bool table[26] = {0}; + for (int i = 0; i < 14; i++) { + if(!table[buf[i] - 'a']) table[buf[i] - 'a'] = true; + else return false; + } + return true; +} + +int main() { + FILE *fp = fopen("input", "r"); + char buf[14] = {0}; + int i = 0; + int c; + while ((c = fgetc(fp)) != EOF) { + if (c < 'a' || c > 'z') continue; + buf[i % 14] = c; + if (i >= 14 && succ(buf)) break; + i++; + } + printf("%d\n", i+1); + return 0; +} |
