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. go http请求基础

    1.请求方法: get post get 加请求参数,请求参数会加到url后面 post加请求参数,请求参数会放在body里面 请求方式:1.直接在url后面加参数  如:http://www.tes ...

  2. angularjs中的路由介绍详解 ui-route

    这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧   首先给大家介绍angular-ui-router的基本用 ...

  3. 初识C++之虚函数

    1.什么是虚函数 在基类中用virtual关键字修饰.并在一个或多个派生类中被又一次定义的成员函数.使用方法格式为: virtual 函数返回类型 函数名(參数表) { 函数体 } 虚函数是实现多态性 ...

  4. win7上python+theano+keras安装

    https://blog.csdn.net/yongjiankuang/article/details/50485610 其实过程很简单,首先说一下安装条件: 1.win7 (32和64都可以,下载安 ...

  5. TouchSlide - 大话主席

    http://www.superslide2.com/TouchSlide/downLoad.html 首  页如何使用查看参数案例演示下载页面交流反馈SuperSlide TouchSlide - ...

  6. idea设置自定义快捷键

    在说明之前,先引入一个非常好的 Intellij Idea中文教程:intelliJ Idea中文教程 一创建模板类 二使用方法备注 在IntellijIdea中我并没有找到直接对某个方法进行注释的模 ...

  7. 转载了个js代码

    document.selection.createRange方法 document.selection.createRange() 根据当前文字选择返回 TextRange 对象,或根据控件选择返回 ...

  8. 华为nova3发布,将支持华为AI旅行助手

    ​​​华为nova3于7月18日18:00在深圳大运中心体育馆举行华为nova 3的发布会,从本次华为nova3选择的代言人-易烊千玺,不难看出新机依然延续nova系列的年轻属性,主打 “高颜值 爱自 ...

  9. 【LeetCode-面试算法经典-Java实现】【118-Pascal&#39;s Triangle(帕斯卡三角形)】

    [118-Pascal's Triangle(帕斯卡三角形(杨辉三角))] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given numRows, generate ...

  10. mysqldump默认参数add-drop-table

    mysqldump默认参数add-drop-table 原创 2014年01月28日 11:35:18 9214 接到一个同事电话,说UAT环境上的一张表被删了,要恢复一下.原来是新项目UAT,从测试 ...