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. 与(&)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...

  2. Django 3.0的新功能

    谷歌翻译的,我修正并且添加了一些内容.凑合看吧. MariaDB的支持 Django现在正式支持MariaDB 10.1和更高版本.有关更多详细信息,请参见MariaDB注释. ASGI支持 Djan ...

  3. CentOS 下 安装 nginx 执行配置命令 ./configure 报错

    CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...

  4. Java FTPClient 大量数据传输的问题(未解决)

    业务需要 需要将一个存储的目标文件里的文件全部拷贝到另一个存储里面去,保持文件结构. 目前采用 org.apache.commons.net.ftp包下相关类来达到ftp连接 获取文件目录信息,拷贝文 ...

  5. c基本语法介绍

    c语言基本语法介绍 1.把常量定义为大写字母形式,是一个很好的编程实践.

  6. 动态指定日志路径(logback)

    实现日志上下文监听,添加路径变量 package com.x.x.x.listener; import ch.qos.logback.classic.Level; import ch.qos.logb ...

  7. 小程序列表循环出来的list是不同接口赋的值

    需求:首页有三个列表,样式形式都是一样的,可以循环展示,但是循环的内容list部分是来自于不同的三个接口. data: { indexList:[{ name: "中考体能突击营" ...

  8. Jmeter测试入门——分析HBase访问服务性能瓶颈

    开启HBase服务 新建线程组,设定线程数为10:  设定请求方法和请求参数: 查看请求的返回结果: 查看服务响应的性能分析结果: 可能出问题的地方:Phoenix.数据库连接池(操作Phoenix)

  9. HiBench成长笔记——(1) HiBench概述

    测试分类 HiBench共计19个测试方向,可大致分为6个测试类别:分别是micro,ml(机器学习),sql,graph,websearch和streaming. 2.1 micro Benchma ...

  10. 安卓:从assets目录下复制文件到指定目录

    有些时候我们直接将某些资源文件内置到apk中,便于直接使用. 1.首先将文件放置在项目/app/src/main/assets目录中 2.功能代码: public void copyFile(Stri ...