Surprising Strings

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

 

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. STL 的方法做的:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm> using namespace std; char s[100]; int main()
{
int len;
int i, j;
map<string, int>ma;
map<string, int>::iterator it;
char sc[3];
int flag; while( gets(s)!=NULL )
{
if(strcmp("*", s)==0)
break;
else
{
len = strlen(s);
if(len==1)
{
printf("%s is surprising.\n", s );
continue ;
} flag=1; //初始化标记变量 j=1;
for(j=1; j<len; j++)
{
ma.clear();
for(i=0; i+j<len; i++)
{
sc[0]=s[i];
sc[1]=s[i+j];
sc[2]='\0';
ma[sc]++;
}
for(it=ma.begin(); it!=ma.end(); it++)
{
if(it->second>1)
{
flag=0; //找到重复的了
break;
}
}
if(flag==0)
{
printf("%s is NOT surprising.\n", s); //不是的话,直接跳出
break;
}
}
if(flag==1)
{
printf("%s is surprising.\n", s );
}
/* else if(flag==0)
{
printf("%s is NOT surprising.\n", S );
} */
}
}
return 0 ;
}

HDU 2736 Surprising Strings的更多相关文章

  1. hdu 2736 Surprising Strings(类似哈希,字符串处理)

    重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...

  2. HDOJ 2736 Surprising Strings

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

  3. [POJ3096]Surprising Strings

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

  4. C - Surprising Strings

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

  5. POJ 3096 Surprising Strings

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

  6. 【字符串题目】poj 3096 Surprising Strings

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

  7. Surprising Strings

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

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

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

  9. HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9

    /* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...

随机推荐

  1. Redis, Memcache, Mysql差别

    在使用Redis过程中,我们发现了不少Redis不同于Memcached.也不同于MySQL的特征. (本文主要讨论Redis未启用VM支持情况) 1. Schema MySQL: 需事先设计 Mem ...

  2. Python基础之迭代器

    迭代器的优点: 1.可以使用for循环遍历: 2.可以节省内存空间: 3.可以有序的访问集合(set)数据结构内的元素. 迭代器的缺点: 只能向前,不能后退. 可迭代对象与不可迭代对象: 可迭代对象: ...

  3. Android内容提供者

    一个应用中的数据库对别人是不会提供直接的访问的,而是提供接口给别人访问,但是一般应用开发的时候都是去获取别人的数据,而不是自己提供数据. 继承ContentProvider: 在Menifest中注册 ...

  4. PlSql加入数据库链接

    Oracle-OraDb10g_home2  ->  配置和移植工具 -> net Manager -> 本地 -> 服务命名 -> 加入(网络服务名自己命名,主机名:要 ...

  5. Jenkins+GitHub+Xcode+fir搭了一个持续集成环境

    enkins+GitHub+Xcode+fir搭了一个持续集成环境 字数826 阅读5699 评论44 喜欢49 原文链接 Coding Duck 今天用Jenkins+GitHub+Xcode+fi ...

  6. k8s部署dashborad

    环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-scheduler ...

  7. (1)安装kvm

    我的环境是redhat虚拟机,版本信息如下: [root@localhost ~]# cat /etc/issue Red Hat Enterprise Linux Server release 6. ...

  8. 第二篇:Filebeat 安装配置

    Filebeat 简介:Filebeat 是一款轻量型日志收集工具,可转发汇总日志.文件等内容.                         其主要特点为:1. 断点续传.(如遇日志转发过程中网络 ...

  9. 嵌入式开发之simulation--- 双目移动dsp机器人

    http://foundy.blog.163.com/blog/static/263383442014112391130207/

  10. [ACM] POJ 3740 Easy Finding (DLX模板题)

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16178   Accepted: 4343 Des ...