Surprising Strings

Surprising Strings
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 5889
Accepted: 3856

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

ZGBG
X
EE
AAB
AABA
AABB
BCBABCC
*

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.

题目的意思是对于每个输入的字符串,先找相邻的字符组成对,检查是否有相同的,再找间隔一个字符的字符对,依次进行,直到第一个与最后一个组成字符对,若是都没有相同的,就是surprising,否则就是NOT surprising。
比如ZGBG:相邻的字符对是:ZG,GB,BG;间隔一个的字符对是:ZB,GG;
最后是ZG;每组中都没有相同的,因此输出surprising!!

<span style="font-size:18px;">#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
using namespace std;
int main()
{
    char str[100];
    int flag,i,j,k,r;
    char s[100][2];
    while(scanf("%s",str)!=NULL)
    {
        memset(s,0,sizeof(s));
        if(str[0]=='*') break;
        flag=0;
        for(i=1; i<strlen(str)-1; i++)
        {
            k=0;
            for(j=0; j+i<strlen(str); j++)
            {
                s[k][0]=str[j];
                s[k][1]=str[j+i];
                k++;
            }

            for(j=0; j<k; j++)
            {
                for(r=j+1; r<k; r++)
                {
                    if(s[j][0]==s[r][0]&&s[j][1]==s[r][1])
                    {
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag==1) printf("%s is NOT surprising.\n",str);
        else printf("%s is surprising.\n",str);
    }
    return 0;
}









</span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值