Poj 3096 surprising strings

Source: Internet
Author: User
Surprising stringstime limit: 1000 msmemory limit: 65536 kbthis problem will be judged on PKU. Original ID: 3096
64-bit integer Io format: % LLD Java class name: Main

The <dfn> D-pairs of a string of letters are the ordered pairs of letters that are distance d from each other. A string is <dfn> D-unique if all of its D-pairs are different. A string is <dfn> surprising if it is D-unique for every possible distance d.

Consider the string zgbg. its 0-pairs are ZG, GB, and BG. since 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 wrongly red by the "puzzling Adventures" column in the December 2003 issueScientific American.

Input

The 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.

Output

For each string of letters, output whether or not it is surprising using the exact output format shown below.

Sample Input
ZGBGXEEAABAABAAABBBCBABCC*
Sample output
ZGBG 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: brute force, using map! In fact, set can also. The meaning is to find a string consisting of two characters (k. At k Distance, two or more strings are the same. So there is no surprising.
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib>10 #include <string>11 #include <set>12 #include <map>13 #include <stack>14 #define LL long long15 #define pii pair<int,int>16 #define INF 0x3f3f3f3f17 using namespace std;18 map<string,int>mp;19 char str[100],tmp[5];20 int main() {21     while(~scanf("%s",str)){22         if(str[0] == ‘*‘) break;23         int len = strlen(str);24         bool flag = true;25         for(int k = 1; k < len; k++){26             mp.clear();27             for(int j = 0; j+k < len; j++){28                 tmp[0] = str[j];29                 tmp[1] = str[j+k];30                 tmp[2] = ‘\0‘;31                 if(mp[tmp]) {flag = false;break;}32                 mp[tmp]++;33             }34             if(!flag) break;35         }36         if(flag) printf("%s is surprising.\n",str);37         else printf("%s is NOT surprising.\n",str);38     }39     return 0;40 }
View code

 

Poj 3096 surprising strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.