day 06 - small optimization & readability improvements
This commit is contained in:
parent
f4d1597de6
commit
43b5a6c6d2
8
06.c
8
06.c
|
@ -10,11 +10,11 @@ int main()
|
|||
|
||||
int ind = 0;
|
||||
int i, j;
|
||||
char s[CHARS] = { 0 }; // yes this takes into account terminating null byte, buffer of chars - 1 chars
|
||||
for (i = CHARS; i > 0; i--) {
|
||||
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)) != NULL)
|
||||
i = (i > CHARS-(p-s)) ? i : CHARS-(p-s);
|
||||
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];
|
||||
|
|
Loading…
Reference in New Issue