POJ 3096:Surprising Strings
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6258 | Accepted: 4072 |
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.
大水题,判断一个字符串中的两个字符组是否相等,一开始是连着的两个字符组,然后看隔一个,隔两个。。。
题目分类上说是考察STL的用法。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
using namespace std; vector <string> zifu; bool pend()
{
int m = zifu.size();
int i,j; for(i=0;i<m;i++)
{
for(j=i+1;j<m;j++)
{
if(zifu[i]==zifu[j])
return false;
}
}
return true;
} int main()
{
string a;
int len,i,k;
while(cin>>a)
{
if(a=="*")
break;
len=a.length(); int flag=1;
for(k=1;k<len;k++)
{
for(i=0;i+k<len;i=i++)
{
string temp="";
temp += a[i];
temp += a[i+k];
zifu.push_back(temp);
}
if(!pend())
{
cout<<a<<" is NOT surprising."<<endl;
flag=0;
break;
}
else
{
zifu.clear();
}
}
if(flag)
cout<<a<<" is surprising."<<endl;
zifu.clear();
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3096:Surprising Strings的更多相关文章
- POJ3096:Surprising Strings(map)
http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- POJ 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: 333 ...
- 【字符串题目】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 ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- HDOJ 2736 Surprising Strings
Surprising Strings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- boost::program_options 解析命令行参数
源码: #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int a ...
- tomcat报错catalina.sh: line 401: /usr/java/jdk1.7.52/bin/java: No such file or directory(转)
原文:https://blog.csdn.net/reblue520/article/details/52588825 将生产服务器的Tomcat目录打包过来后解压后,启动Tomcat后,发现如下问题 ...
- 牛客小白月赛3---G 旅游(树形dp)
题目链接:https://www.nowcoder.com/acm/contest/87/G 分析: 1.对于点cur,dp[cur][0]表示在该点住宿:dp[cur][1]表示其某个子结点住宿,自 ...
- 用 Heapster 监控集群【转】
Heapster 是 Kubernetes 原生的集群监控方案.Heapster 以 Pod 的形式运行,它会自动发现集群节点.从节点上的 Kubelet 获取监控数据.Kubelet 则是从节点上的 ...
- tools.windows.bat#批处理
关于%~ %~I - 删除任何引号("),扩展 %I %~fI - 将 %I 扩展到一个完全合格的路径名 %~dI - 仅将 %I 扩展到一个驱动器号 %~pI - 仅将 %I 扩展到一个路 ...
- uboot配置和编译过程详解
根据朱有鹏老师讲解整理 一.uboot主Makefile分析 1.uboot version确定(Makefile的24-29行) include/version_autogenerated.h文件是 ...
- 用Python实现简单的服务器【新手必学】
如何实现服务器... socket接口是实际上是操作系统提供的系统调用.socket的使用并不局限于Python语言,你可以用C或者JAVA来写出同样的socket服务器,而所有语言使用socket的 ...
- 八、Delphi10.3读取JSON文件,并修改JSON数组一条内容后保存到文件
一.我们有一个JSON文件,如下: { "在野": [ { "城池": 0, "武将": 74, "登场年": 190 ...
- ①java环境变量配置以及简单的dos框操作
DOS:英文全称Disk Operation System,即磁盘操作系统,是个人电脑上使用的一种操作系统,并曾是世界上最广泛使用的操作系统. JDK: 英文全称Java Development Ki ...
- J. Cola
J. Cola time limit per test 4.0 s memory limit per test 64 MB input standard input output standard o ...