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 ...
随机推荐
- 微信二次分享的JSSDK的调用
网页端微信的二次分享如果不调用分享的SDK,分享之后就不会带有标题.描述 .缩略图 微信分享SDK调用 引入 <script src="//res.wx.qq.com/open/js/ ...
- MyBatis-Insert、Delete、Update的注意事项
MyBatis-Insert.Delete.Update的注意事项 插入/更新乱码的解决 出现插入乱码,首先要考虑数据库的编码集是不是UTF-8 如果数据库的编码无误,查看MyBatis的全局配置文件 ...
- 十二 事务&安全问题&隔离级别
事务 transaction,指一组操作,里面包含许多单一逻辑,只要一个逻辑没有执行成功,那么都算失败.所有的数据都回到最初的状态(回滚). 为什么要有事务? 确保逻辑的成功,例子:银行转账 事务针对 ...
- 【转】深入分析JAVA IO(BIO、NIO、AIO)
IO的基本常识 1.同步 用户进程触发IO操作并等待或者轮询的去查看IO操作是否完成 2.异步 用户触发IO操作以后,可以干别的事,IO操作完成以后再通知当前线程继续处理 3.阻塞 当一个线程调用 r ...
- Matplotlib 图形绘制
章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...
- 01.DesignParttern设计模式,简单工厂,工厂方法,抽象工厂三大工厂的区别与联系
工厂用来生产对象,对象具有方法和属性. 简单工厂的缺点(简单工厂并不是23中设计模式): 工厂类的职责相对过重,增加新的产品,需要修改工厂类的判断逻辑,违背开闭原则: JDK源 ...
- 8051单片机中访问int中字节的方法
在使用单片机中,unsigned int 占2个字节,unsigned char 占一个字节.而单片机是实行的字节寻址.16字节的bit寻址实在是不好用, 不好用在不能建数组. 在实际的开发过程中,要 ...
- BubbleSort
看见了一些乱乱的东西,就想着整理一下,基础的冒泡排序 //BubbleSort #include<iostream> using namespace std; void BubbleSor ...
- 51nod 1765 谷歌的恐龙
一开始看到了期望吓半死..然后弱弱的写了一下式子.设∑是出去m项之后的和,∑' 是m项的和. E=(n/m)*(∑'/m)+(n/m)*((n-m)/n)*(∑'/m+∑/(n-m))+(n/m)*( ...
- CLion的使用
配置远程Linux编译器 实现目标:1.将项目中的源码和target和Linux服务器同步.2.代码在服务器端运行 配置ToolChains setting -> Build,Execution ...