Surprising Strings
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的更多相关文章
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- HDOJ 2736 Surprising Strings
Surprising Strings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- POJ 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: 333 ...
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
- 【字符串题目】poj 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6193 Accepted: 403 ...
- [ACM] POJ 3096 Surprising Strings (map使用)
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5783 Accepted: 379 ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
- hdu 2736 Surprising Strings(类似哈希,字符串处理)
重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...
随机推荐
- Spring注解驱动开发之AOP
前言:现今SpringBoot.SpringCloud技术非常火热,作为Spring之上的框架,他们大量使用到了Spring的一些底层注解.原理,比如@Conditional.@Import.@Ena ...
- Android GetTimeAgo(时间戳转换几天前,几分钟前,刚刚等)
package com.studychen.seenews.util; import android.content.Context; /** * Created by tomchen on 2/26 ...
- IOS 中使用token机制来验证用户的安全性
登录的业务逻辑{ http:是短连接. 服务器如何判断当前用户是否登录? // 1. 如果是即时通信类:长连接. // 如何保证服务器跟客户端保持长连接状态? // ...
- 4 Visual Effects 视觉效果 读书笔记 第四章
4 Visual Effects 视觉效果 读书笔记 第四章 Well, circles and ovals are good, but how about drawing r ...
- iOS---小经验分享
1.字符串在block中得赋值 定义一个全局变量,<字符串>当这个字符串用copy修饰的时候,然后再在block中赋值,当在block块之外访问时,不能得到字符创的值.此时字符串应该设置为 ...
- js阻塞ui进程涉及的知识点整理
项目进行中遇到了同步ajax阻塞ui线程阻塞的问题,原因是执行两个同步ajax请求为一次完整的方法,因业务需求需要循环执行这个方法,检查后台返回的数据正确,但是由于ajax请求时间过长,考虑增加遮罩层 ...
- 【译】x86程序员手册40-10.5初始化的例子
10.5 Initialization Example初始化的例子 译注:本来想把这个例子全部注释完,但由于对intel汇编实不熟悉,有太多的伪指令,本人也是免强看懂,所以就不再做翻译了. $TITL ...
- SweetAlert如何实现点击Confirm之后自动关闭
swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary ...
- pil - pillow 的版本
pip install PIL python2版本 pip install pillow python3版本
- CAD参数绘制填充(网页版)
填充是CAD图纸中不可或缺的对象,在机械设计行业,常常需要将零部件剖开,以表现其内部的细节,而这些被剖开的截面会用填充来表示:在工程设计行业,一些特殊的材料或地形,也会用填充来表示. js中实现代码说 ...