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. 由内省引出JavaBean的应用

    IntroSpector-->javaBean-->特殊的java类 get和set方法 ReflectPoint pt1 = new ReflectPoint(3,5); String ...

  2. IntelliJ IDEA 识别一个类所属的jar包package

    IntelliJ IDEA 识别一个类所属的jar包package 按住ctrl,鼠标移动上去,不要点击: 有木有快捷键? ctrl+alt+B直接就过去了:需要再跳回来:

  3. 服务器性能之CPU

    有时我们会发现开发的应用在CPU核数一样的虚拟服务器上性能表现出较大的差异,这是为什么呢?上次有童鞋问到我这样一个问题,所以我根据自己的理解给大家简说下! CPU生产商为了提高CPU的性能,通常做法是 ...

  4. 微信小程序 - gulp插件压缩(代码、图片等)

    最后更新时间: 2018.7.18 :更新了所有package.json插件版本以及修复极个别问题. 2018.8.12 : 增加提示,所有标签必须闭合(不然打包会报错) 2018.10.13:需要用 ...

  5. UNP学习笔记(第六章 I/O复用)

    I/O模型 首先我们将查看UNIX下可用的5种I/O模型的基本区别: 1.阻塞式I/O 2.非阻塞式I/O 3.I/O复用(select和poll) 4.信号驱动式I/O(SIGIO) 5.异步I/O ...

  6. HBase中Region, store, storefile和列簇的关系

    转自:http://zhb-mccoy.iteye.com/blog/1543492 The HRegionServer opens the region and creates a correspo ...

  7. VueJS组件通过props自定义事件

    父组件是使用 props 传递数据给子组件,但如果子组件要把数据传递回去,就需要使用自定义事件! 我们可以使用 v-on 绑定自定义事件, 每个 Vue 实例都实现了事件接口(Events inter ...

  8. 笔记本中LVDS屏与eDP屏的比较

    LVDS,即Low Voltage Differential Signaling,是一种低压差分信号技术接口.它是美国NS公司(美国国家半导体公司)为克服以TTL电平方式传输宽带高码率数据时功耗大.E ...

  9. 硬件问题大杂烩&Coffee lake框图

    PCB阻抗控制 https://www.cnblogs.com/lifan3a/articles/6095372.html 1.高速差分信号串联AC耦合电容什么请况下要做镂空处理: (1)为了阻抗匹配 ...

  10. EAI G4-lidar ROS配置

    (1)使用命令创建 ydlidar_ws 工作空间,并将 G4 资料包内的 ROS 驱动包 ydlidar 下载到ydlidar_ws/src 目录下,切换到 ydlidar_ws 工作空间下并重新进 ...