1. 程式人生 > >【TOJ 2176】Surprising Strings

【TOJ 2176】Surprising Strings

form for span while The relevant itself unique AI

描述

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

輸入

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.

輸出

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

樣例輸入

ZGBG
X
EE
AAB
AABA
AABB
BCBABCC
*

樣例輸出

ZGBG is surprising.
X is surprising.
EE is surprising.
AAB is surprising.
AABA is surprising.
AABB is NOT surprising.
BCBABCC is NOT surprising.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    while(cin>>a,a!="*")
    {
        
int flag=1,i,p=0; if(a.size()==1||a.size()==2) flag=1; else { while(p<=a.size()-2) { map<string,int>ma; for(i=0;i<a.size()-p-1;i++) { string x,p1,p2; p1=a[i],p2=a[i+p+1]; x=p1+p2; if(ma[x]!=0) { flag=0; break; } ma[x]++; } if(flag==0) break; p++; } } if(flag==1) cout<<a<<" is surprising."<<endl; else cout<<a<<" is NOT surprising."<<endl; } return 0; }

【TOJ 2176】Surprising Strings