/* Problem and solution written by Thomas Tang */ #include #include #include #define TRUE 1 #define FALSE 0 void check(char *line, int p) { int d, i, j, start, stop, max; int prevIsDot; max = strlen(line); for (d = -1; d <= 1; d += 2) { /* forward and backward */ prevIsDot = FALSE; for (i = p+d; (0 <= i) && (i < max); i += d) { if (isalnum(line[i]) || (line[i] == '_')) { prevIsDot = FALSE; } else { if (line[i] == '.') { if (prevIsDot) break; prevIsDot = TRUE; } else { break; } } } i -= d; /* back track one step */ if (line[i] == '.') i -= d; /* back track one more step */ if (d == -1) { start = i; } else { stop = i; } } if ((p-start == 0) || (stop-p == 0)) return; for (i = start; i <= stop; i++) { printf("%c", line[i]); line[i] = ' '; } printf("\n"); } main() { char line[100]; int i, j, k; for (;;) { gets(line); if (strcmp(line, "EOF") == 0) break; for (i = 0; i < strlen(line); i++) { if (line[i] == '@') { check(line, i); } } } }