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 ...
随机推荐
- [书目20141009]《ReWork》
ReWork1: ============= 引言篇INTRODUCTION开局篇FIRST 新的现实缷负篇TAKEDOWNS 忘了“现实世界” 哪来的从错误中学习 计划即瞎猜 何必壮大? 工作狂 受 ...
- [翻译] API测试最佳实践 - 组织你的测试
组织你的测试 适用级别:初学者 在最底层,一个测试步骤(Test Step)用来验证一个单独的操作.组合若干测试步骤到测试用例,允许你验证那些被分隔出来的一个一个的功能,这些功能是应用程序所需要的.接 ...
- 1、QQ装机部落---腾讯软件
亲,赚钱快人一步,我给你推荐QQ装机部落!大品牌,口碑好,知名软件,绿色无毒,每天结算,回报高!到这里注册:http://zjbl.qq.com/#/?invid=476058088 返利网邀请码立即 ...
- Linux下PPPoE Server测试环境搭建
1.1 服务器软件安装 安裝PPPoE Server 所需的软件: 安装ppp模块: sudo apt-get install ppp //一般默认下已安装 安装rp-pppoe,从网络上下载安 ...
- UI概念体系要素
结构.渲染.交互.数据. 要素.呈现.交互 1)UI(组成)要素:结构 2)布局: 3)渲染: 4)事件处理: 5)数据:
- python照相机模型与增强现实
这次试验主要实现以平面和标记物进行姿态估计以及增强现实的应用. 一.以平面和标记物进行姿态估计(1)下面演示的是一个简单例子:如何在一副图像上放置一个立方体,原图如下: (2)先提取两幅JPG图像的S ...
- confluence的安装
参考链接:https://www.ilanni.com/?p=11989 一.什么是confluence confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实 ...
- vs2019装了WDK后,编译其他vc工程,提示无法打开文件"msvcprtd.lib"
今天安装了vs2019,而后又安装了wdk,随便写了一个控制台测试程序,居然报错.网上也查了一圈,也没有得到解决.报错内容如下: MSB8038:已启用Spectre缓解,但找不到Spectre缓解库 ...
- ssd运行过程中遇到的bug
1.出现以下错误: 没有添加环境变量: https://github.com/weiliu89/caffe/issues/4 可以看到当前PYTHONPATH不再ssd1里面,所以需要修改,修改之后就 ...
- mysql常用命令用法
Mysql帮助文档地址:http://dev.mysql.com/doc/ 1.创建数据库: create database database_name; 2.选择数据库: use database_ ...