C - Surprising Strings

题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising

,否则输出surprising。



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.

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
char s[500];
char t[500];
int main()
{
int i,j;
int n;
while(scanf("%s",s)!=EOF)
{
if(s[0]=='*')
break;
n = strlen(s);
bool flag = true;
for(i=0;i<n;i++)
{
if(!flag)
break;
map<string,int>mapp;
for(j=0;j+i+1<n;j++)
{
if(!flag)
break;
t[0] = s[j];
t[1] = s[j+i+1];
t[2] = '\0';
if(mapp[t]>0)
{
printf("%s is NOT surprising.\n",s);
flag = false;
}
else
mapp[t]++;
}
}
if(flag)
cout<<s<<" is surprising."<<endl;
}
return 0;
}

C - Surprising Strings的更多相关文章

  1. [POJ3096]Surprising Strings

    [POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...

  2. HDOJ 2736 Surprising Strings

    Surprising Strings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. POJ 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5081   Accepted: 333 ...

  4. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

  5. 【字符串题目】poj 3096 Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6193   Accepted: 403 ...

  6. Surprising Strings

    Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...

  7. [ACM] POJ 3096 Surprising Strings (map使用)

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5783   Accepted: 379 ...

  8. POJ 3096:Surprising Strings

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

  9. hdu 2736 Surprising Strings(类似哈希,字符串处理)

    重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...

随机推荐

  1. SGU 163.Wise King

    一道题目长的水题.... 总结就一句话,给出n个(-3~3)的数,一个数m,取任意个数是使这些数的m次幂之和最大. code #include <iostream> #include &l ...

  2. java设计模式——单例(Singleton)模式

    在某些场景,你需要找到一个承担职责的对象,并且这个对象是他所属类的唯一实例.此时可以使用单例模式. 单例模式的意图是为了确保一个类有且仅有一个实例,并为他提供一个全局的访问点.创建一个担当独一无二角色 ...

  3. apple iphone 3gs 有锁机 刷机 越狱 解锁 全教程(报错3194,3014,1600,短信发不出去等问题可参考)

    以自身经历列步骤如下:(基本思路就是刷6.1.6,越狱,降级基带,解锁) 一.准备工作 1.下载3gs 6.1.6官方固件.地址:http://act.feng.com/wetools/index.p ...

  4. java浮点数剖析

    定点数表达法的缺点在于其形式过于僵硬,固定的小数点位置决定了固定位数的整数部分和小数部分,不利于同时表达特别大的数或者特别小的数.计算机系统采纳了所谓的浮点数表达方式.这种表达方式利用科学计数法来表达 ...

  5. linux 获取cpu百分比

    vmstat 1 |head -n 4 |tail -n 1 |awk '{print $13}'

  6. 汇总前端最最常用的JS代码片段

    html5选择器 //参数均接收一个合法的css选择器 element = document.querySelector('.foo,.bar');//返回带有foo或者bar样式类的首个元素 ele ...

  7. ajax验证用户名和找回密码参考

    // JavaScript Document function chkname(form){ var user = form.user.value; if(user == ''){ alert('请输 ...

  8. linux 和 ubuntu 修改主机名

    原始主机名:jeepend-VirtualBox linux 修改方法: 1.使用secure CRT或其他方式 用root用户 登入系统.2.在终端输入: #hostname [修改后的主机名]3. ...

  9. Windows Open with Sublime Text

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text] "Icon&q ...

  10. HTML部分标签的含义(2)

    1,ul标签,添加新闻信息列表 使用ul标签,信息无先后顺序 这些列表就可以用ul-li标签来完成 语法:<ul> <li>信息</li> <li>信息 ...