POJ 3096:Surprising Strings

来源:互联网 发布:淘宝店铺页头装修 编辑:程序博客网 时间:2024/06/05 10:10

Surprising Strings
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 6258 Accepted: 4072

Description

The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs are different. A string is 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 inspired by the "Puzzling Adventures" column in the December 2003 issue of Scientific 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.

大水题,判断一个字符串中的两个字符组是否相等,一开始是连着的两个字符组,然后看隔一个,隔两个。。。

题目分类上说是考察STL的用法。

代码:

#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <string>#include <cstring>using namespace std;vector <string> zifu;bool pend(){int m = zifu.size();int i,j;for(i=0;i<m;i++){for(j=i+1;j<m;j++){if(zifu[i]==zifu[j])return false;}}return true;}int main(){string a;int len,i,k;while(cin>>a){if(a=="*")break;len=a.length();int flag=1;for(k=1;k<len;k++){for(i=0;i+k<len;i=i++){string temp="";temp += a[i];temp += a[i+k];zifu.push_back(temp);}if(!pend()){cout<<a<<" is NOT surprising."<<endl;flag=0;break;}else{zifu.clear();}}if(flag)cout<<a<<" is surprising."<<endl;zifu.clear();}return 0;}



0 0