由于判断是否相等的字符串在AA-ZZ之间,直接开一个27*27的数组寻址,使用27进制记数,比数AA=0, ZZ=26*27+26,这样中间的每个字符串各有自己唯一的位置,便于判断各字符是否互不相同
#include<stdio.h>
#include<string.h>
int main()
{
char s[80];
while (scanf("%s", s), s[0] != '*')
{
int i, j, d, index, flag = 1, l = strlen(s);
int a[27 * 27];
for (d = 1; d < l && flag; d++)
{
for (i = 0; i < 27 * 27; i++)
a[i] = 0;
for (j = 0; j + d < l; j++)
{
index = (s[j] - 'A') * 27 + (s[j + d] - 'A');
if (!a[index])
a[index] = 1;
else
{
flag = 0;
break;
}
}
}
printf(flag ? "%s is surprising.\n" : "%s is NOT surprising.\n", s);
}
return 0;
}