HDU 2736 Surprising Strings
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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 <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm> using namespace std; char s[100]; int main()
{
int len;
int i, j;
map<string, int>ma;
map<string, int>::iterator it;
char sc[3];
int flag; while( gets(s)!=NULL )
{
if(strcmp("*", s)==0)
break;
else
{
len = strlen(s);
if(len==1)
{
printf("%s is surprising.\n", s );
continue ;
} flag=1; //初始化标记变量 j=1;
for(j=1; j<len; j++)
{
ma.clear();
for(i=0; i+j<len; i++)
{
sc[0]=s[i];
sc[1]=s[i+j];
sc[2]='\0';
ma[sc]++;
}
for(it=ma.begin(); it!=ma.end(); it++)
{
if(it->second>1)
{
flag=0; //找到重复的了
break;
}
}
if(flag==0)
{
printf("%s is NOT surprising.\n", s); //不是的话,直接跳出
break;
}
}
if(flag==1)
{
printf("%s is surprising.\n", s );
}
/* else if(flag==0)
{
printf("%s is NOT surprising.\n", S );
} */
}
}
return 0 ;
}
HDU 2736 Surprising Strings的更多相关文章
- hdu 2736 Surprising Strings(类似哈希,字符串处理)
重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...
- HDOJ 2736 Surprising Strings
Surprising Strings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- 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 ...
- Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...
- [ACM] POJ 3096 Surprising Strings (map使用)
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5783 Accepted: 379 ...
- HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9
/* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...
随机推荐
- <LeetCode OJ> 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 教你用squid做CDN把公司做到上市
我们都知道CDN(内容分发网络)是用来给网站加速用的,通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络的“边缘”,使用户可以就近取得所需的内容,以提高用户访问网站 ...
- Spring事务管理之声明式事务管理-基于注解的方式
© 版权声明:本文为博主原创文章,转载请注明出处 案例 - 利用Spring的声明式事务(TransactionProxyFactoryBean)管理模拟转账过程 数据库准备 -- 创建表 CREAT ...
- angularjs中的路由介绍详解 ui-route
这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧 首先给大家介绍angular-ui-router的基本用 ...
- PHP 依据IP地址获取所在城市
有这种需求,须要依据用户的IP地址,定位用户所在的城市. 本文记录性文章,无逻辑性.有这样需求的朋友.能够直接拷贝使用.直接上代码,不需赘述. <? php header('Content-Ty ...
- html 绘图阴影和透明度
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- ORACLE 表空间使用率查询
SELECT A.TABLESPACE_NAME, A.BYTES / (1024 * 1024 * 1024 ) TOTAL, B.BYTES / (1024 * 1024 * 1024 ) USE ...
- Rocchio算法
一.引子 查询扩展(Query Expansion)是信息检索领域的一个重要话题. 一方面.用户本身可能会出错,他会输入一些错别字,比方把"冯小刚",错写成"冯晓刚&qu ...
- ELK之jason配置nginx文件等多个配置文件
[root@web02 ~]# cat /etc/logstash/conf.d/nginx.conf input { file { path => "/var/log/nginx/a ...
- 在mac上独立安装PHP环境
1.http://dditblog.com/blog_418.html 2.http://www.jianshu.com/p/0456dd3cc78b