POJ 3096 : Surprising Strings

来源:互联网 发布:python telnetlib详解 编辑:程序博客网 时间:2024/06/06 15:00

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。
枚举比较即可。

include

include

using namespace std;

int main()
{
string s;
while(getline(cin,s))
{
if(s[0]==’*’)
return 0;
int x=s.length();

    int flag=0;    for(int i=0;i<x;i++)    {        for(int j=i+1;j<x;j++)        {            if(s[i]==s[j])            {                //cout<<s[i]<<s[j]<<endl;                 for(int k=1;k<x;k++)                {                    if(s[i+k]==s[j+k]&&i+k<x&&j+k<x)                    {                        flag=1;                        }                   }            }        }    }    if(flag==0)        cout<<s<<" is surprising."<<endl;        else            cout<<s<<" is NOT surprising."<<endl;}return 0;

}

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 微信不能说语音怎么办 微信语音发不了怎么办 吃鸡语音用不了怎么办 要杀我的人见面怎么办 转晕了想吐怎么办 原地转圈头晕恶心想吐怎么办 孩子吃凉的呕吐头还晕怎么办 孩子转晕了想吐怎么办 转圈晕了想吐怎么办 我爸总是骂我妈怎么办 转圈转的想吐怎么办 大便干燥拉不出来怎么办 吹完头发很干燥怎么办 腿摔伤了结痂疼怎么办 蹭wifi被禁止后怎么办 电脑wifi给拉黑怎么办 电脑想用无线网怎么办 中路被对方打崩了怎么办 英雄联盟队友太坑怎么办 匹配被王者虐了怎么办 lol碰到嘴臭的怎么办 小婴儿脾气大怎么办呢? 玩游戏输入法会跳出出来怎么办 逆水寒fps太低怎么办 我dcj没地速怎么办 电焊看久眼睛疼怎么办 装修忘了窗帘盒怎么办? 纹眉导致眼肿了怎么办 哭泣引起的眼肿怎么办 在酒店忘记拉窗帘了怎么办 湿气重喉咙有痰怎么办 眼睛上火了肿了怎么办 陌陌直播没人看怎么办 陌陌直播没人气怎么办 我真的爱上你了怎么办 弯腰时间久了腰疼怎么办 斗鱼pk输的怎么办 领导当着人骂我怎么办 被老板骂了应该怎么办 三星s7关机键掉了怎么办 主播遇到黑粉怎么办