Surprising StringsTime Limit: 1000 MS Memory Limit: 65536 KTotal Submissions: 4813 Accepted: 3175 DescriptionThe D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs are different. A string is surprising if it is D-unique for every possible distance D. consider the string ZGBG. its 0-pairs are ZG, GB, and BG. sin Ce these three pairs are all different, ZGBG is 0-unique. similarly, the 1-pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is 1-unique. finally, the only 2-pair of ZGBG is ZG, so ZGBG is 2-unique. thus ZGBG is surprising. (Note that the fact that ZG is both a 0-pair and a 2-pair of ZGBG is irrelevant, because 0 and 2 are different distances .) acknowledgement: This problem Is too red by the "Puzzling Adventures" column in the December 2003 issue of Scientific American. inputThe input consists of one or more nonempty strings of at most 79 uppercase letters, each string on a line by itself, followed by a line containing only an asterisk that signals the end of the input. outputFor each string of letters, output whether or not it is surprising using the exact output fo Rmat shown below. sample InputZGBGXEEAABAABAAABBBCBABCC * Sample OutputZGBG is surprising. X is surprising. EE is surprising. AAB is surprising. AABA is surprising. AABB is NOT surprising. BCBABCC is NOT surprising. sourceMid-Central USA 2006 I originally wanted to use a dictionary tree to write this question, but when I write it, I suddenly realized that the string can be regarded as a 27-digit number with two digits. Just mark it. [cpp] # include <stdio. h> # include <string. h> # include <math. h> char s1 [100], a [1000]; int main () {int I, j, n, m, s, t, l; char c1, c2; while (scanf ("% s", s1 )! = EOF) {if (strcmp (s1, "*") = 0) {break;} l = strlen (s1); for (I = 1; I <= L-1; I ++) {memset (a, 0, sizeof (a); for (j = 0; j <= L-1; j ++) {if (j + I> L-1) {break;} c1 = s1 [j]; c2 = s1 [j + I]; s = (int) (c1-'A') * 27 + (int) (c2-'A'); if (! A [s]) {a [s] = 1 ;}else {break ;}}if (j + I <L-1) {break ;}} if (I = l) {printf ("% s is surprising. \ n ", s1);} else {printf (" % s is NOT surprising. \ n ", s1) ;}} return 0 ;}