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 ...
随机推荐
- Day9 - K - Yue Fei's Battle HDU - 5136
Yue Fei is one of the most famous military general in Chinese history.He led Southern Song army in t ...
- 前端学习笔记系列一:2 Vue的单文件组件
(1)非单文件vue组件和单文件vue组件的一般写法 一个完整的vue组件会包括三个部分:一是template模板部分,二是js程序逻辑部分,三是css样式部分.每个组件都有属于自己的模板,js和样式 ...
- Java设计模式之Iterator模式
分类: [java]2013-07-15 10:58 917人阅读 评论(0) 收藏 举报 所谓Iterator模式,即是Iterator为不同的容器提供一个统一的访问方式.本文以java中的容器为例 ...
- 题解 UVA10298 【Power Strings】
此题我写的是后缀数组SA解法,如果不会后缀数组的可以跳过本篇blog了. 参考文献:罗穗骞 2009集训队后缀数组论文 前记 最近学后缀数组,肝了不少题,也分出了后缀数组的几个题型,看这题没有后缀数组 ...
- LR的深入理解资料汇集
今天面试被问到LR的算法的梯度和正则化项,自己不太理解,所以找了一些相关资料,发现LR的算法在梯度下降,正则化和sigmoid函数方面都有很深的研究,期间也发现一些比较好的资料,记录一下. 这篇论文推 ...
- python-python基础6(面向对象)
一.面向对象编程 编程范式 编程是 程序 员 用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程 , 一个程序是程序员为了得到一个任务结果而编写的一组指令的集合,正所谓条条大路通罗马 ...
- C语言三种整数类型
1,int 是 C 语言的基本整数类型,可以满足我们处理一般数据的需求. C 语言还提供了四个可以修饰 int 的关键字:short.long.signed,以及 unsigned. 利用这四个关键字 ...
- CodeForces - 869A The Artful Expedient
题意:有两个序列X和Y,各含n个数,这2n个数互不相同,若满足xi^yj的结果在序列X内或序列Y内的(xi,yj)对数为偶数,则输出"Karen",否则输出"Koyomi ...
- JS 判断是否为安卓或IOS系统
其实很简单,代码如下<script type="text/javascript"> var device = navigator.userAgent; || devic ...
- 【微信小程序】数组操作
Page({ data: { list:[{ id:1, name:'应季鲜果', count:1 },{ id:2, name:'精致糕点', count:6 },{ id:3, name:'全球美 ...