27 lines
471 B
C
27 lines
471 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define CHARS 14 // set this to 4 for part 1
|
|
|
|
int main()
|
|
{
|
|
char *p;
|
|
char c;
|
|
|
|
int ind = 0;
|
|
int i, j;
|
|
char s[CHARS] = { 0 }; // only need a CHARS-1 buffer, not CHARS
|
|
for (i = 0; i < CHARS; i++) {
|
|
c = getchar();
|
|
if ((p = strchr(s,c)) && i > p-s)
|
|
i = p-s;
|
|
// shift seen chars
|
|
for (j = CHARS - 2; j > 0; j--) // - 2 for null byte
|
|
s[j] = s[j - 1];
|
|
s[0] = c;
|
|
ind++;
|
|
}
|
|
printf("found at %d\n", ind);
|
|
return(0);
|
|
}
|