POJ 3096 Surprising Strings(STL)
练习STL中的map。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <map> 5 using namespace std; 6 map <string,int> p; 7 int main() 8 { 9 int i,j,len,z; 10 char str[101]; 11 char o[4]; 12 while(scanf("%s",str)!=EOF) 13 { 14 if(str[0] == '*')break; 15 len = strlen(str); 16 z = 1; 17 for(i = 1;i <= len-1;i ++) 18 { 19 p.clear(); 20 for(j = 0;j+i<=len-1;j ++) 21 { 22 o[0] = str[j]; 23 o[1] = str[j+i]; 24 o[2] = '\0'; 25 if(!p[o]) 26 p[o] ++; 27 else 28 z = 0; 29 } 30 } 31 if(z) 32 printf("%s is surprising.\n",str); 33 else 34 printf("%s is NOT surprising.\n",str); 35 } 36 return 0; 37 }