Surprising Strings(map类)

http://poj.org/problem?id=3096

题意容易理解,开始直接暴力,还是用map写下吧,熟练一下;

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<string>
 4 #include<map>
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     char s[100];
10     char t[5];
11     int n,i;
12     map <string,int> mymap;
13 
14     while(~scanf("%s",s))
15     {
16         if(s[0] == '*')
17             break;
18 
19         n = strlen(s);
20         bool flag = true;
21         int start,end;
22 
23         for(i = 0; i <= n-2 &&flag; i++)
24         {
25             mymap.clear();
26             for(start = 0,end = start+i+1; end < n;start++,end++)
27             {
28                 t[0] = s[start];
29                 t[1] = s[end];
30                 t[2] = '';
31                 if(mymap[t] != 0)
32                 {
33                     flag = false;
34                     break;
35                 }
36                 else
37                    mymap[t]++;
38             }
39         }
40         if(flag)
41             printf("%s is surprising.
",s);
42         else printf("%s is NOT surprising.
",s);
43     }
44     return 0;
45 }
View Code
原文地址:https://www.cnblogs.com/LK1994/p/3370954.html