POJ 3096 Surprising Strings
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5081 | Accepted: 3336 |
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.
Source
定义D-pairs表示取字符串s中相距为D的两个字母所构成的字母对,该字母对中两个字母的位置顺序与他们在主串s中的位置顺序一致
定义D-unique表示,若从字符串s中取出所有相距为D的字母对D-pairs,且这些D-pairs都是独一无二的,那么成字符串s是一个D-unique串
D的取值范围为0~s.len()-2
假如字符串s对于所有的D都有D-unique成立,则字符串s是令人惊讶的 = =
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<string> using namespace std; char str[]; int main(){ //freopen("input.txt","r",stdin); map<string,int> mp;
while(~scanf("%s",str) && str[]!='*'){
int flag=;
int len=strlen(str);
//printf("str=%s\n",str);
string tmp;
int blank=;
for(int i=;i<len-blank && flag;i++){
tmp="";
mp.clear();
for(int i=;i<len-blank && flag;i++){
tmp=tmp+str[i]+str[i+blank];
//cout<<"-------- "<<tmp<<endl;
if(mp[tmp])
flag=;
mp[tmp]=;
tmp="";
}
blank++;
}
if(flag)
printf("%s is surprising.\n",str);
else
printf("%s is NOT surprising.\n",str);
}
return ;
}
POJ 3096 Surprising Strings的更多相关文章
- 【字符串题目】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(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
- [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 ...
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
- [水] POJ 3096
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7659 Accepted: 487 ...
随机推荐
- 高效的数据压缩编码方式 Protobuf
一. protocol buffers 是什么? Protocol buffers 是一种语言中立,平台无关,可扩展的序列化数据的格式,可用于通信协议,数据存储等. Protocol buffers ...
- 【POJ】【2187】Beauty Contest
计算几何/旋转卡壳 学习旋转卡壳请戳这里~感觉讲的最好的就是这个了…… 其实就是找面积最大的三角形?...并且满足单调…… 嗯反正就是这样…… 这是一道模板题 好像必须写成循环访问?我在原数组后面复制 ...
- Linux监听进程是否存在,并加入定时任务
前言 我们在linux主机上可能需要一直运行某一服务,如果关机后或者误杀,使得服务停止,从而影响日常的任务.比如一BI项目数据库的抽取,使用Taskctl调度,在每天固定时间进行数据的抽取,如果主机上 ...
- Javascript 中“靠”的使用
Javascript中call的使用自己感觉蛮纠结的,根据文档很好理解,其实很难确定你是否真正的理解. call 方法应用于:Function 对象调用一个对象的一个方法,以另一个对象替换当前对象.c ...
- Bootstrap学习js插件篇之提示框
案例 受到Jason Frame开发的jQuery.tipsy插件的启发,我们才把这个工具提示插件做的更好,而且此插件不依赖图片,只是使用CSS3来实现动画效果,并使用data属性存储标题. 将鼠标悬 ...
- 拍案惊奇!9款神奇的jQuery/CSS3经典插件
款非常给力的jQuery/CSS3经典插件,插件包括CSS3图片特效.jQuery动画菜单.jQuery时尚登录表单等,一起来看看这些jQuery插件. .CSS3图片重力感应特效 这是一款应用重力感 ...
- 火速提升Android仿真器的运行速度 ——仿真器Genymotion
一.问题概述 Android开发中会使用仿真器测试应用,但不管你使用Eclispe ADT还是Android Studio仿真器都是基于arm架构的,运行起来都很慢,光启动就要花费很多时间,都不知道它 ...
- MongoDB学习笔记(四)--索引 && 性能优化
索引 基础索引 ...
- 【Hadoop】mapreduce采用多进程与spark采用多线程比较
转自:Mapreduce多进程与spark多线程 Apache Spark的高性能一定程度上取决于它采用的异步并发模型(这里指server/driver 端采用的模型),这与Hadoop 2.0(包括 ...
- tiny210(s5pv210)移植u-boot(基于 2014.4 版本号)——移植u-boot.bin(打印串口控制台)
在之前我们移植的代码中,都没看到明显的效果,这节我们实现控制台的信息打印. 在上节.我们看到调用 relocate_code 重定位.在 u-boot 的帮助文档 doc/README.arm-rel ...