这道题其实也不是很难,只是有些小细节需要注意而已,刚开始想着用C++的string类型,后来想到都是取出字符中的两个字符而已,就想到了用数组了,嘿嘿... // source code of submission 758043, Zhongshan University Online Judge System #include <iostream> #include <cstdio> #include <cstring> int main() { int flag,len,i,j,k,dis,sup; char sub[10000][2]; char s[100]; while(gets(s),strcmp(s,"*")) { len = strlen(s); flag = 1,sup = 1; //注意赋值的位置 if(len==1||len==2) flag = 1; else { for(dis = 0;dis<len-2;dis++) { if(sup==0) break; for(i = 0;i < len-dis-1;i++) sub[i][0] = s[i],sub[i][1] = s[i+dis+1]; for(j = 0;j<i-1;j++) { if(sup==0) break; for(k = j+1;k < i;k++) //一开始只是sub[j][*]和sub[j+1][*],导致wrong answer { if(sub[j][0]==sub[k][0]&&sub[j][1]==sub[k][1]) {flag = 0;sup = 0;break;} } } } } if(flag==1) printf("%s is surprising./n",s); else printf("%s is NOT surprising./n",s); } return 0; }