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. Codis的安装

    其他环境准备: 安装JDK,安装Zookeeper 1.创建codis账户 useradd codis passwd codis 2.解压codis3.1.3-go1.7.4-linux.tar.gz ...

  2. maven setting.xml 配置(有效)

    <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...

  3. 又一次遇到Data truncation: Data too longData truncation: Data too long问题

    往MySQL的blob字段上传文件,结果又出现了Data truncation: Data too longData truncation: Data too long异常. 我的第一反应是查看/et ...

  4. 【X240 QQ视频对方听不到声音】解决方法

    [X240 QQ视频对方听不到声音]解决方法: win7为例: 右键点击右下角的"小喇叭"图标,点击"录音设备",显演示样例如以下图: watermark/2/ ...

  5. java查看工具jinfo-windows

    Generates configuration information. This command is experimental and unsupported. Synopsis jinfo [  ...

  6. cheap louis vuitton outlet

    <h1>louis vuitton outlet store</h1>2 nigerian networking systems chosen seeing that enem ...

  7. 某个时间段关闭API

    def bet(): if 000000 < int(time.strftime("%H%M%S", time.localtime())) < 90000: print ...

  8. xcode常见报错调试【原创】

    BMKGeoCodeSearch 反向地理编码一直失败 Location 申请的key的安全码与代码中build id不一样,修改成一样就OK了 新建一个类,将百度地图的定位功能封装起来以后,定位的代 ...

  9. 02-cookie案例-显示用户上次访问网站的时间

    package cookie; import java.io.IOException;import java.io.PrintWriter;import java.util.Date; import ...

  10. VSTS跟Kubernetes整合进行CI/CD

    利用VSTS跟Kubernetes整合进行CI/CD   为什么VSTS要搭配Kubernetes? 通常我们在开发管理软件项目的时候都会碰到一个很头痛的问题,就是开发.测试.生产环境不一致,导致开发 ...