poj 3096 Surprising Strings
来源:互联网 发布:尚品宅配怎么样 知乎 编辑:程序博客网 时间:2024/06/01 22:42
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
ZGBGXEEAABAABAAABBBCBABCC*
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.
恩,题意比较难理解,但其实是道水题。
题意:给你一个字符串,看一看是不是符合D-unique的D-pair是否各不相同。
D-unique指的是两个字符之间相隔的字符的个数(D)。D-pair就是就是间隔为D个字符的一对字符(这里看一看示例差不多就懂了)
思路:map暴力枚举
#include <iostream>#include <cstdio>#include <cstring>#include <map>using namespace std;char s[80];char ans[3];bool doit(char *s){ int i,j; int l=strlen(s); for(i=0;i<l-1;++i) { map<string,bool>ha; for(j=0;j<l-i;++j) { ans[0]=s[j]; ans[1]=s[j+i+1]; ans[2]=0; if(ha[ans])return 0; ha[ans]=1; } } return 1;}int main(){ while(~scanf("%s",s)&&s[0]!='*') { if(doit(s))printf("%s is surprising.\n",s); else printf("%s is NOT surprising.\n",s); } return 0;}
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096 Surprising Strings
- POJ 3096 Surprising Strings
- POJ 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096:Surprising Strings
- Surprising Strings(POJ -3096
- poj 3096 Surprising Strings
- poj-3096-Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096 Surprising Strings
- poj 3096 Surprising Strings
- 海量数据处理利器greenplum——初识
- 4AppBarLayout滑动原理
- Velocity学习--如何判断一个对象是否为空(null)
- 递归退出的条件
- Codeforces Round #362 (Div. 2)-D. Puzzles
- poj 3096 Surprising Strings
- 设置text-overflow文本溢出隐藏时的对齐问题
- greenplum数据库引擎探究
- Java lambda 函数式接口
- JMeter使用之常见问题问答
- Greenplum技术浅析
- CoreTelephony运营商信息
- GLSurfaceView.Renderer,openGL的渲染接口
- Listview+RadioButton实现单选