int main(void) { FILE *in=fopen("calfflac.in", "r"), *out=fopen("calfflac.out", "w"); char sample[STRING_LIMIT + 1], c; char normalized[STRING_LIMIT + 1]; int i, j; pal result; i = j = 0; while ((c = (char)fgetc(in)) != -1) { sample[i++] = c; if (VALID_CHAR(c)) normalized[j++] = tolower(c); } sample[i] = '\0'; fclose(in); get_longest_pal2(&result, normalized); fprintf(out, "%d\n", result.length); for (i=0, j=0; i < strlen(sample); i++) { if (VALID_CHAR(sample[i])) j++; if (j - 1 >= result.start) fputc(sample[i], out); if (j == result.start + result.length) break; } fputc('\n', out); fclose(out); return 0; }
void optimize(char *code, int options) { unsigned int i, j; /* We're calling strlen here because it is brought up more than once in the code below */ unsigned int len = strlen(code); /* We're only setting options to know if we need to optimize debug symbols */ SET_OPTIONS_VARIABLE(options); /* Return if code is empty string */ if (len == 0) return; /* Loop through code and add the OK characters */ for (i = 0, j = 0; i < len; i++) { /* Add pairless valid characters */ if (i < (len - 2) && code[i] == OPPOSITE(code[i + 1])) { /* Skip next character */ i += 1; } else if (VALID_CHAR(code[i])) { /* Add character */ code[j] = code[i]; j++; } } /* Add null terminator */ code[j] = '\0'; /* Recurse */ if (len != j) { optimize(code, options); } }