Surprising Strings
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6258   Accepted: 4072

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 <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
using namespace std; vector <string> zifu; bool pend()
{
int m = zifu.size();
int i,j; for(i=0;i<m;i++)
{
for(j=i+1;j<m;j++)
{
if(zifu[i]==zifu[j])
return false;
}
}
return true;
} int main()
{
string a;
int len,i,k;
while(cin>>a)
{
if(a=="*")
break;
len=a.length(); int flag=1;
for(k=1;k<len;k++)
{
for(i=0;i+k<len;i=i++)
{
string temp="";
temp += a[i];
temp += a[i+k];
zifu.push_back(temp);
}
if(!pend())
{
cout<<a<<" is NOT surprising."<<endl;
flag=0;
break;
}
else
{
zifu.clear();
}
}
if(flag)
cout<<a<<" is surprising."<<endl;
zifu.clear();
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. 关于xamarin.forms在MVVM情况下如何DisplayActionSheet
  2. 【POJ 1390】Blocks
  3. jquery对url中的中文解码
  4. nodejs随记02
  5. Bash中各种以$开头的特殊变量的含义
  6. ruby&amp;mongo_mapper
  7. Java学习-035-JavaWeb_004 -- JSP include 指令
  8. Js 插件修改及优化总结
  9. 实测Eclipse连接小米2S调试问题
  10. 修改Eclipse的WorkSpace保持数[转载]
  11. C#键盘事件处理(来源网上)
  12. Linux TCP连接数修改
  13. Python 学习系列----第一章:基础知识
  14. Jmeter学习系列----3 配置元件之计数器
  15. VS2017 nlog源码查看报错
  16. this view is not constrainted......
  17. hdoj2089(入门数位dp)
  18. HNOI2018题解
  19. jQuery -- 监听input、textarea输入框值变化
  20. VS2008 试图运行未注册64位调试器组件

热门文章

  1. MyISAM/Innodb的区别
  2. Nginx 的优势
  3. netcore webCache缓存
  4. gitlab导入备份数据
  5. Hive的原理和基本用法
  6. ThinkPHP 3.2 生成静态页面
  7. Helm 架构【转】
  8. dMd----攻防世界
  9. 云时代架构阅读笔记十四——我对Hash算法的理解
  10. linux 下office软件推荐