-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday06.c
49 lines (41 loc) · 758 Bytes
/
day06.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int has_dupes(const char *begin, const char *end)
{
const char *p, *q;
for (p = begin; p < end; ++p)
{
for (q = p + 1; q < end; ++q)
{
if (*p == *q)
{
return 1;
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
int count;
char *input;
int i;
size_t len;
if (argc < 3)
{
exit(2);
}
count = strtol(argv[1], NULL, 10);
input = argv[2];
len = strlen(input);
for (i = 0; i < len - count; ++i)
{
if (!has_dupes(input + i, input + i + count))
{
break;
}
}
printf("%d\n", i + count);
return 0;
}