Surprising Strings
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: Accepted:
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 -pairs are ZG, GB, and BG. Since these three pairs are all different, ZGBG is -unique. Similarly, the -pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is -unique. Finally, the only -pair of ZGBG is ZG, so ZGBG is -unique. Thus ZGBG is surprising. (Note that the fact that ZG is both a -pair and a -pair of ZGBG is irrelevant, because and are different distances.) Acknowledgement: This problem is inspired by the "Puzzling Adventures" column in the December issue of Scientific American. Input The input consists of one or more nonempty strings of at most 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.
Source Mid-Central USA
#include <iostream>
#include <cstdio>
#include<set>
#include <vector>
#include <cstring>
#include <list>
#include <queue>
#include <algorithm>
#include<functional>
#include <stack>
#define MAXN 200 + 3
#define INF 0x3f3f3f3f
using namespace std;
//直接枚举+hash+set 随便过
char s[MAXN];
inline int Hash(char a, char b)
{
return (a - 'a') * + b - 'a';
}
int main()
{
ios::sync_with_stdio();
while (cin >> s, s[] != '*')
{
set<int> S;
int L = strlen(s);
int l;
for (l = ; l < L; l++)
{
S.clear();
for (int i = ; i + l < L; i++)
S.insert(Hash(s[i], s[i + l]));
if (S.size() != L - l)
break;
}
if (l == L)
cout << s << " is surprising." << endl;
else
cout << s << " is NOT surprising." << endl;
}
return ;
}

Surprising Strings的更多相关文章

  1. [POJ3096]Surprising Strings

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

  2. C - Surprising Strings

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

  3. HDOJ 2736 Surprising Strings

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

  4. POJ 3096 Surprising Strings

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

  5. HDU 2736 Surprising Strings

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

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

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

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

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

  8. POJ 3096:Surprising Strings

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

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

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

随机推荐

  1. OAuth 开放授权 Open Authorization

    http://oauth.net/ http://tools.ietf.org/html/rfc6749 http://reg.163.com/help/help_oauth2.html 网易通行证O ...

  2. 【Hibernate】多对多关系的表达

    User.hbm.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate ...

  3. 用css制作圆环图表 (vue,sass)

    效果图: 思路 :在一个容器里再放两个矩形,每个矩形都占一半,给这两个矩形都设置溢出隐藏,当去旋转矩形里面的圆形的时候,溢出部分就被隐藏掉了,这样就可以达到想要的效果. 代码-html: <di ...

  4. [Tunny]Grunt基础介绍

    [黄映焜/Tunny,20140711] Grunt是一个JavaScript任务管理器,对于需要反复重复的任务,例如压缩.编译.单元测试.代码检查等,自动化工具可以减轻你的劳动,简化你的工作. 本文 ...

  5. Android下多彩的StatusView的实现

    概述 在上一个博文 Anroid沉浸式状态栏中提到了,画了一个图,这个图简单将我们的状态栏分为不同的2个维度来看状态栏.其中涉及的概念我不在赘诉,请返到Anroid沉浸式状态栏再去认识下这几个概念.本 ...

  6. 这是一条立了Flag的不归路

    时间2017年7月11日 14:48:40 首次激活博客园的博客来进行学习记录,立下了不算远大的小目标,下一步就是要一步一步的往前走. Java是目前最普遍的使用语言之一,作为一名测试,本应该去学习更 ...

  7. js 动态添加表单 table tr

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. day23-1 isinstance、issubclass和反射

    目录 isinstance和issubclass 反射(hasattr,getattr,setattr,delattr) isinstance和issubclass isinstance(obj,cl ...

  9. CSS 实现斑马条纹

    Part.1 linear-gradient() linear-gradient() 函数用于创建一个线性渐变的 "图像".为了创建一个线性渐变,你需要设置一个起始点和一个方向(指 ...

  10. java正则表达式进阶运用20181023

    直接上代码. package org.jimmy.autotranslate20181022.test; import java.util.regex.Matcher; import java.uti ...