Surprising Strings
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6193   Accepted: 4036

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. 题目分析:一个字符串例如:AABB,字符的两两组合为:间距为0时:AA AB BB
间距为1时:AB AB (出现相同情况,可以判断该串为 not surprise )
间距为2时: AB
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm> using namespace std; struct node
{
char a;
char b;
bool operator == (const node &x)const{
return a==x.a&&b==x.b; //重载定义==符号 判断两个结构体相等
}
}q[10000]; int main()
{
char s[100];
int i, j, k, ll;
int len;
while(scanf("%s", s) && strcmp(s, "*")!=0 ){
len = strlen(s);
if(len<=2){
printf("%s is surprising.\n", s);
}
else{
bool flag=false;
for(i=0; i<=len-2; i++)
{
int e=0;
for(j=0; j+i<len; j++)
{
q[e].a=s[j]; q[e++].b=s[j+i+1];
}
for(k=0; k<e; k++)
{
for(ll=k+1; ll<e; ll++)
{
if(q[k] == q[ll]){
flag=true; break;
}
}
}
if(flag==true){
break;
}
}
if(flag==true)
printf("%s is NOT surprising.\n", s);
else
printf("%s is surprising.\n", s);
}
}
return 0;
}

【字符串题目】poj 3096 Surprising Strings的更多相关文章

  1. POJ 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5081   Accepted: 333 ...

  2. [ACM] POJ 3096 Surprising Strings (map使用)

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5783   Accepted: 379 ...

  3. POJ 3096 Surprising Strings(STL map string set vector)

    题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...

  4. POJ 3096:Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6258   Accepted: 407 ...

  5. C - Surprising Strings

                                   C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...

  6. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

  7. [POJ3096]Surprising Strings

    [POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...

  8. HDOJ 2736 Surprising Strings

    Surprising Strings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

随机推荐

  1. Linux下不重启永久修改hostname

    LINUX下不重启永久修改hostname 1.如果只是修改hostname可以通过如下命令 hostname newHostname   注意:这种修改方式只有当前有效,等服务器重启后hostnam ...

  2. linux中find的用法

    找所在目录的文件用 find -name “file*” -print  #注意不要用加文件路径,查找文件也好用双双引号括住: 也可以 find ./ -name “file*” -print

  3. DFRobot万物互联大赛第一轮

    前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. DF搞的这个比赛还挺有趣:micro:bit × OBLOQ DF创客社区玩转物联网挑战赛,一边在写文章一边在爱奇艺上看着印度电影 ...

  4. 记录MySQL运行的SQL

    对照Oracle功能去学习Mysql总会发现亮点 Oracle中通过日志挖掘这一技能,能够找到以前运行过的全部记录: Mysql中也提供了3种方法{验证过的,我会记录详细做法} 方法1:{已验证} 记 ...

  5. 基于UML的需求分析和系统设计个人体会

    阅读了http://www.uml.org.cn/oobject/201405123.asp文章之后,对使用UML进行系统的需求分析和设计有了一个基础的理解.在此做一下整理.   1.项目开始阶段 项 ...

  6. 关于proplists:get_value/2 与lists:keyfind/3 的效率比较

    关于proplists:get_value/2 与lists:keyfind/2 的效率 早有比较,已出结论,lists:keyfind/2 的效率要好很多,好些人都是直接用或者做过它们之间的比较测试 ...

  7. 扒一扒P2P风控的底牌(转)

    互联网金融,这里面水就太深了,能当理财买的一般有两类,一个是货币基金,比如余额宝,这个大家已经十分清楚了,没什么风险, 但问题就是收益越来越低.实在是不过瘾了.而另外一种就是P2P理财了,收益很高,也 ...

  8. 部署mongodb中需要注意的调参

    部署mongodb的生产服务器,给出如下相关建议: 使用虚拟化环境: 系统配置 1)推荐RAID配置 RAID(Redundant Array of Independent Disk,独立磁盘冗余阵列 ...

  9. 多媒体开发之---h264 高度和宽度获取

    ( School of Computer Science & Technology, Soochow University,SuZhou 215006:) Abstract: H.264 is ...

  10. cocos2dx 3.2+ 项目创建与问题总汇

    本文为Cocos2d-x 3.x 全平台(Android,iOS)新手开发配置教程攻略,希望对大家有所帮助.由于这篇文章是面对新手的. 所以有些地方会啰嗦一些,请勿见怪. 假设教程中有错误.欢迎指正. ...