【字符串题目】poj 3096 Surprising Strings
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6193 | Accepted: 4036 |
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. 题目分析:一个字符串例如:AABB,字符的两两组合为:间距为0时:AA AB BB
间距为1时:AB AB (出现相同情况,可以判断该串为 not surprise )
间距为2时: AB
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm> using namespace std; struct node
{
char a;
char b;
bool operator == (const node &x)const{
return a==x.a&&b==x.b; //重载定义==符号 判断两个结构体相等
}
}q[10000]; int main()
{
char s[100];
int i, j, k, ll;
int len;
while(scanf("%s", s) && strcmp(s, "*")!=0 ){
len = strlen(s);
if(len<=2){
printf("%s is surprising.\n", s);
}
else{
bool flag=false;
for(i=0; i<=len-2; i++)
{
int e=0;
for(j=0; j+i<len; j++)
{
q[e].a=s[j]; q[e++].b=s[j+i+1];
}
for(k=0; k<e; k++)
{
for(ll=k+1; ll<e; ll++)
{
if(q[k] == q[ll]){
flag=true; break;
}
}
}
if(flag==true){
break;
}
}
if(flag==true)
printf("%s is NOT surprising.\n", s);
else
printf("%s is surprising.\n", s);
}
}
return 0;
}
【字符串题目】poj 3096 Surprising Strings的更多相关文章
- POJ 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: 333 ...
- [ACM] POJ 3096 Surprising Strings (map使用)
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5783 Accepted: 379 ...
- POJ 3096 Surprising Strings(STL map string set vector)
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 &qu ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
- [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 ...
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
随机推荐
- JAVA使用外部字体将文字生成图片,并使用FontMetrics居中文字
需求: 1.用户输入文字,根据外部字体,将文字生成图片 2.输出的文字需要居中在图片中显示 遇到的问题: 1.如何导入外部字体?使用Java的Font类,所有的字体都是系统安装过的 2.每次用户输入的 ...
- IT项目管理-----给年轻工程师的十大忠告
http://blog.csdn.net/hbqhdlc/article/details/6201179给年轻工程师的十大忠告 诸位,咱当电子工程师也是十余年了,不算有出息,环顾四周,也没有看见几个有 ...
- Oracle 字段类型
Oracle 字段类型 http://www.cnblogs.com/lihan/archive/2010/01/06/1640547.html 字段类型 描述 字段长度及其缺省值 CHAR (siz ...
- 无刷新URL 更新
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 使用Chrome(PC)调试移动设备上的网页
最早开始调试移动端网页时,本人都是采取PC上改几行代码,手机上刷新一下看效果这种笨方法来开发的,效率低而且容易让人抓狂.最近偶然发现原来可以使用PC上的浏览器来调试移动设备,不由得感叹相逢恨晚. 工具 ...
- java 方法重写原则
方法重写应遵循“三同一小一大”原则: “三同”:即方法名相同,形参列表相同,返回值类型相同: “一小”:子类方法声明抛出的异常比父类方法声明抛出的异常更小或者相等: “一大”:子类方法的访问修饰符应比 ...
- 从epoll构建muduo-12 多线程入场
mini-muduo版本号传送门 version 0.00 从epoll构建muduo-1 mini-muduo介绍 version 0.01 从epoll构建muduo-2 最简单的epoll ve ...
- HUAWEI HiAI亮相华为开发者生态大会 助力应用AI开发实现加速度
6月23日,在2018华为终端·全球合作伙伴及开发者大会AI分论坛体验区的一角,被层层叠叠的人群围得水泄不通.站在最前面的一名体验者,正跟随着“快手短视频”APP上不断出现的小人左右扭动,每完成一个动 ...
- AI生万物,新世界的大门已敞开
四月是万物复苏的时节,一年一度的GMIC全球移动互联网大会也在这个时间如期而至,在4月26日-28日的会议期间,有超过三百位行业专家进行了精彩的演讲,更有数万名现场观众感受到思维碰撞迸发出的火花. 作 ...
- linux下网卡绑定
网卡绑定的作用:1.冗余,防止单点故障 2.防止传输瓶颈 1.交换机端口绑定: system-view link-aggregation group 1 mode manual 比如把端口1和2进行绑 ...