poj3096
C++的标准模版库的应用
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6625 | Accepted: 4309 |
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.
Source



#include<cstdio>
#include<cstring>
char str[];
int main(){
int i,j,k;
int count;
int len;
while(scanf("%s",str)==&&strcmp(str,"*")!=){
len=strlen(str);
if(len<=){
printf("%s is surprising.\n", str);
continue;
}
for(i=,count=;i<len&&count!=; i++){
count=;
for(j=i+,k=;j<len;j++,k++){
if(str[j]==str[k]) count++;
if(count==) break;
}
}
if(count==)
printf("%s is NOT surprising.\n", str);
else
printf("%s is surprising.\n", str);
}
return ;
}
poj3096的更多相关文章
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- POJ3096:Surprising Strings(map)
http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- acm常见算法及例题
转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法: (1)枚举. (poj17 ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
随机推荐
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何配置虚拟轴 TC3
在Motion上添加一个NC Task 在Axis上右击添加一个轴,类型为Continuous Axis 在PLC上右击添加新项,然后添加一个PLC项目 在引用中添加TC2_MC2的库引用 ...
- unity3D打造skybox淡入淡出 - 移动开发
原地址:http://www.it2down.com/it-mobile/426479.htm 当前位置: IT异常查询网 » unity3D打造skybox淡入淡出 - 移动开发 www.it2do ...
- mui.ajax返回type为abort
最近在使用h5和mui开发app,发现mui.ajax有一个小bug 情况一: 参数和请求路径无误,但是总是调起失败的回调函数,打印出 type=abort (终止请求) 原因: mui.ajax默认 ...
- CoffeeScript 学习笔记
1.什么叫 CoffeeScript CoffeeScript 是一种新的编程语言,构建于 JavaScript 之上.CoffeeScript 提供了一种简洁的语法,对 Python 或 Ruby ...
- XX年年终总结---重新飞跃
XX年年终总结---重新飞跃 写之前先解释一下为什么是年终总结,由于在提高班学习,每年结束于暑假:新的一年開始于9月. 肚子里的墨水已经找不到新的词语来形容时间过得快了,一年结束了.还有一年又结束了: ...
- Atitit.研发管理---api版本号策略与版本控制
Atitit.研发管理---api版本号策略与版本控制 1. 1.2.1版本概述1 2. 3主版本号策略2 3. 1PATCH版本策略2 3.1. 1.2.2.1次版本号策略2 表3-1 APR中支持 ...
- Unix环境高级编程(一)
Unix基础知识1.引言2.Unix体系结构3.登陆4.文件和目录5.输入和输出6.程序和进程7.出错和处理8.用户标示9.信号10.时间值11.系统调用和库函数12.小结
- mount rootfs
主要用到的命令为pivot_root,可man 8 pivot_root了解用法. 1. pivot_root - change the root filesystem pivot_root new_ ...
- FD_CLOEXEC用法及原因_转
转自:使用FD_CLOEXEC实现close-on-exec,关闭子进程无用文件描述符 我们经常会碰到需要fork子进程的情况,而且子进程很可能会继续exec新的程序.这就不得不提到子进程中无用文件描 ...
- Help Hanzo lightof 1197 求一段区间内素数个数,[l,r] 在 [1,1e9] 范围内。r-l<=1e5; 采用和平常筛素数的方法。平移区间即可。
/** 题目:Help Hanzo lightof 1197 链接:https://vjudge.net/contest/154246#problem/M 题意:求一段区间内素数个数,[l,r] 在 ...