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 ...
随机推荐
- [转]C++之多态性与虚函数
面向对象程序设计中的多态性是指向不同的对象发送同一个消息,不同对象对应同一消息产生不同行为.在程序中消息就是调用函数,不同的行为就是指不同的实现方法,即执行不同的函数体.也可以这样说就是实现了“一个接 ...
- Guava Files 源码分析(二)
createTempDir()之后就没有什么有意思的函数了,基本上都是对Java IO函数操作的聚合,只看一个simplifyPath() /** * Returns the lexically cl ...
- 【BZOJ】【2752】【HAOI2012】高速公路(Road)
数学期望/线段树 然而又是一道road= =上一道是2750…… 下次不要一看期望题就弃疗么…… 期望题≠不可做题……!! 其实在这题中,期望就是(所有情况下 权值之和)/(总方案数) 因为是等概率抽 ...
- 【12c】root container 和 pdb 的一些差别
Where\what ? root pdb 备注 Control files and redo log files Y belongs to the CDB and not to a spec ...
- how to configure logback for Mybatis to print my SQL
To log SQL statements for particular mybatis mapper set DEBUG (TRACE to see query parameters and res ...
- 第九章 Redis过期策略
注:本文主要参考自<Redis设计与实现> 1.设置过期时间 expire key time(以秒为单位)--这是最常用的方式 setex(String key, int seconds, ...
- [Ajax] AJAX初体验之-在博客中添加无刷新搜索
现在博客很流行,相信应该上网时间稍微长点的朋友都会在这或者在那的有一个自己的博客.对于一些有一定能力的朋友,可能更喜欢自己去下载一个博客程序来架设一个自己的博客,而不是使用一些博客网站提供的服务.而大 ...
- C# 的三种序列化方法
序列化是将一个对象转换成字节流以达到将其长期保存在内存.数据库或文件中的处理过程.它的主要目的是保存对象的状态以便以后需要的时候使用.与其相反的过程叫做反序列化. 序列化一个对象 为了序列化一个对象, ...
- python 斐波拉契数列数列
'''斐波拉契数列'''def Fibonacci(n): first, next = 0, 1 i = 0; while i < n: print next first, next = nex ...
- .NET-WEB网站部署的过程中需要注意的问题
--部署的网站的文件夹需要有IIS_USER权限(写权限) --部署的网站在外网不能访问:一般是由于防火墙的限制导致的.配置防火墙就可以.