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)递归和分治法. ( ...
随机推荐
- 各大网站css初始化代码【转】
文章来源:http://blog.sina.com.cn/s/blog_71ed1b870101a52w.html 腾讯QQ官网(http://www.qq.com)样式初始化 body,ol,ul, ...
- javascript中按位操作的应用,如何快速取整 判断字符串是否是包含某字符串
最近在看最基础的<javascript高级程序设计>看的灰常慢,看到按位运算这里,突然反思,这种鬼操作到底有什么实际的应用呢? 按位运算符有6个 & 按位与:a & b | ...
- GBDT--简单理解
梳理 1.Model Ensemble 能够分为三大类:Bagging,Boosting. Stacking. 2.Boosting能够说是一个思想(框架),而Adaboost等算法仅仅是其一个子类, ...
- 《memcached全面剖析》
第1章 memcached的基础 1.1 memcached是什么? memcached是高性能的分布式内存缓存服务器. 一般的做法是,通过缓存数据库查询结果,减少数据库访问次数,以提高动态web应用 ...
- Bootstrap组件之导航
.nav--指定列表元素为导航组件. .nav-tabs--指定导航组件的样式为标签页: .nav-pills--指定导航组件的样式为胶囊式标签页: .nav-stacked--指定标签页的样式为垂直 ...
- Flex读取txt文件里的内容报错
Flex读取txt文件里的内容 1.详细错误例如以下 2.错误原因 读取文件不存在 var file:File = new File(File.applicationDirectory.nativeP ...
- 盘点20款主流应用FPS,最Skr帧率测试方法都在这里!
无论是手机端还是PC端,画面的流畅度一直被用户视为衡量应用视觉体验的重要标准.用户往往通过主观感觉把视觉体验分为两种状态: 流畅视觉:行云流水,一气呵成: 非流畅视觉:“卡顿”.“抖动”.“迟钝 ...
- hdu3208 Power of Integer
/** 题目:H - Power of Integer 链接:https://vjudge.net/contest/152887#problem/H 题意:给出区间[a, b],问你区间[a, b]所 ...
- 配置LANMP环境(1)-- 安装虚拟机VMware与安装CentOS7.2系统
一.安装虚拟机VMware 1.下载VMware傻瓜式安装 2.配置 二.安装CentOS7.2系统 镜像下载链接 1.放入ios镜像文件之后,启动虚拟机,选择7.0+的 ...
- Scrapy爬虫入门系列4抓取豆瓣Top250电影数据
豆瓣有些电影页面需要登录才能查看. 目录 [隐藏] 1 创建工程 2 定义Item 3 编写爬虫(Spider) 4 存储数据 5 配置文件 6 艺搜参考 创建工程 scrapy startproj ...