C - Surprising Strings

來源:互聯網
上載者:User

標籤:des   style   blog   color   os   io   strong   for   

                               C - Surprising Strings

題意:輸入一段字串,如果在同一距離下有兩個字串相同輸出Not surprising
,否則輸出surprising。


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.



#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <map>using namespace std;char s[500];char t[500];int main(){    int i,j;    int n;    while(scanf("%s",s)!=EOF)    {        if(s[0]=='*')            break;         n = strlen(s);         bool flag = true;         for(i=0;i<n;i++)         {             if(!flag)                break;             map<string,int>mapp;             for(j=0;j+i+1<n;j++)             {                 if(!flag)                    break;                t[0] = s[j];                t[1] = s[j+i+1];                t[2] = '\0';                if(mapp[t]>0)                {                    printf("%s is NOT surprising.\n",s);                    flag = false;                }                else                    mapp[t]++;             }         }            if(flag)cout<<s<<" is surprising."<<endl;    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.