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的更多相关文章

  1. POJ3096:Surprising Strings(map)

    http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...

  2. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...

  3. POJ 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5081   Accepted: 333 ...

  4. 【字符串题目】poj 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6193   Accepted: 403 ...

  5. [ACM] POJ 3096 Surprising Strings (map使用)

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5783   Accepted: 379 ...

  6. C - Surprising Strings

                                   C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...

  7. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

  8. [POJ3096]Surprising Strings

    [POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...

  9. HDOJ 2736 Surprising Strings

    Surprising Strings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 《Redis深度历险:核心原理和应用实践》千帆竞发——分布式锁

  2. 《算法技术手册》George T. Heineman(作者)epub+mobi+azw3

    内容简介 开发健壮的软件需要高效的算法,然后程序员们往往直至问题发生之时,才会去求助于算法.<算法技术手册>讲解了许多现有的算法,可用于解决各种问题.通过阅读它,可以使您学会如何选择和实现 ...

  3. linux环境下查看tomcat日志

    1.先切换到:cd usr/local/tomcat5/logs 2.tail -f catalina.out 3.这样运行时就可以实时查看运行日志 Ctrl+c 是退出tail命令. alt+E+R ...

  4. IOS UIKIT_EXTERN, __attribute__((visibility ("default"))) 是啥玩意?

    问题提出 在学习IOS时候,碰到一个函数NSStringFromCGPoint (UIGeometry.h) 其原型是 UIKIT_EXTERN NSString *NSStringFromCGPoi ...

  5. Jackson自定义反序列化

    // 设置jackson时间反系列化格式 SimpleModule module = new SimpleModule(); module.addDeserializer(Date.class, ne ...

  6. POJ 2386 Lake Counting 八方向棋盘搜索

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53301   Accepted: 26062 D ...

  7. java 移动距离

    移动距离 X星球居民小区的楼房全是一样的,并且按矩阵样式排列.其楼房的编号为1,2,3- 当排满一行时,从下一行相邻的楼往反方向排号. 比如:当小区排号宽度为6时,开始情形如下: 1 2 3 4 5 ...

  8. Ubuntu 19.10将使用GCC 9作为默认编译器

    作为我们这一周期一直期待的变化,Ubuntu 19.10升级到GCC 9作为GCC 8的默认系统编译器. Ubuntu 19.10(和Ubuntu 20.04 LTS)将使用GCC 9 stable作 ...

  9. SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

    [oracle@jtwy02 ~]$ sqlplus '/as sysdba' SQL*Plus: Release 11.2.0.4.0 Production on Sat Oct 13 14:14: ...

  10. DB2的简单操作

    转 最近在看db2,边读边写了一些,记下来,虽然写的乱七八糟.以备后用. 这些都写的很简单.我觉得也算是一些简单的操作吧,有些也是摘自别人的blog具体是引用哪的就不太记得了. 一.DB2两种注释写法 ...