Surprising Strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 294    Accepted Submission(s): 209

Problem 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.
 

自己写的代码一直wa....求高手

#include <iostream>
#include <string>
#include <string.h>
#include <cctype>
using namespace std;
///**wa代码**/
bool judge(string a,string b)
{
for(int i=0; i<a.length(); i++)
{
for(int j=i+1; j<a.length(); j++)
{
if(a[i]==a[j] && b[i]==b[j])
{
return true;
}
}
}
return false;
}
int main()
{
string s="";
while(cin>>s && s[0] != '*')
{
string str,ans1,ans2,table1,table2,count1,count2;
str=ans1=ans2=table1=table2=count1=count2="";
int k=0;
str=s;
for(int i=0; i<s.length(); i++)
{
if(islower(s[i]))
s[i]=toupper(s[i]);
else
s[i]=s[i];
}
// cout<<s<<" "<<str<<endl;
if(s.length()>1)
{
for(int i=0; i<s.length()-1; i++)
{
ans1+=s[i];
ans2+=s[i+1];
}
}
if(s.length()>2)
{
for(int i=0; i<s.length()-2; i++)
{
table1+=s[i];
table2+=s[i+2];
}
}
if(s.length()>3)
{
for(int i=0; i<s.length()-3; i++)
{
count1+=s[i];
count2+=s[i+3];
}
} if(!judge(ans1,ans2) && !judge(table1,table2) &&!judge(count1,count2))
cout<<str<<" is surprising."<<endl;
else
cout<<str<<" is NOT surprising."<<endl;
/*cout<<ans1<<" ";
cout<<ans2<<" ";
cout<<table1<<" ";
cout<<table2<<" "<<count1<<" "<<count2<<endl;*/
}
} /**别人正确代码**/
#include<iostream>
#include<string>
using namespace std;
int map[26][26];
char str[10000];
int change(char a)
{
return (int)(a-'A');
}
int main()
{
int i,j;
while(cin>>str&&str[0]!='*')
{
int len=strlen(str);
int flag=0;
for(i=0; i<=len-2; i++)
{
memset(map,0,sizeof(map));
for(j=0; j<=len-2-i; j++)
{
int x=change(str[j]);
int y=change(str[j+i+1]);
if(map[x][y])
{
flag=1;
break;
}
else map[x][y]=1;
}
if(flag==1) break;
}
if(flag) cout<<str<<" is NOT surprising."<<endl;
else cout<<str<<" is surprising."<<endl; }
return 0;
}

HDOJ 2736 Surprising Strings的更多相关文章

  1. HDU 2736 Surprising Strings

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

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

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

  3. [POJ3096]Surprising Strings

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

  4. C - Surprising Strings

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

  5. POJ 3096 Surprising Strings

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

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

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

  7. Surprising Strings

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

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

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

  9. POJ 3096:Surprising Strings

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

随机推荐

  1. 增强SEO的div+css命名规则

    页头:header登录条:loginBar标志:logo侧栏:sideBar广告:banner导航:nav子导航:subNav菜单:menu子菜单:subMenu搜索:search滚动:scroll页 ...

  2. Mac 实用工具

    命令行常用工具: Iterm2 也是一个终端命令行工具,支持多工作区,使用清爽 http://www.iterm2.com/documentation.html 给你的命令行 代码上色 Solariz ...

  3. Java与C#的语法区别(不断更新中...)

    1.static关键字: 在java中静态成员能够被对象和类名调用: 在C#中,静态成员只能被类调用不能被对象调用. 2.for循环: 在java中可以在for前面添加标记,然后在for循环中可以br ...

  4. OCP-1Z0-051-题目解析-第31题

    31. Evaluate the following SQL commands: SQL>CREATE SEQUENCE ord_seq INCREMENT BY 10 START WITH 1 ...

  5. Node-Webkit作者王文睿:桌面应用的全新开发方式

    摘要:最近两年,Node.js技术越来越火,基于它所开发的应用也纷纷出现在大家面前,其中Node-Webkit就是这样的一个开源框架,它允许开发者使用Web技术开发桌面应用. Node-Webkit是 ...

  6. JavaScript快速入门(一)——JavaScript概览

    JavaScript是什么? JavaScript的诞生 在1995年前后,当时世界上的主流带宽为28.8Kbps,现在世界平均下载带宽为21.9Mbps(数据来源于http://www.netind ...

  7. 5.中文问题(自身,操作系统级别,应用软件的本身),mysql数据库备份

     第一层因素: mysql的自身的设置 mysql有六处使用了字符集.分别为:client .connection.database.results.server .system. mysql&g ...

  8. 大话spring.net之IOC

    在学习Spring.NET这个控制反转(IoC)和面向切面(AOP)的容器框架之前,我们先来看一下什么是控制反转(IoC). 控制反转(Inversion of Control,英文缩写为IoC).也 ...

  9. OCA读书笔记(6) - 配置Oracle网络环境

    6.Configuring the Oracle Network Environment su - grid装grid时自动创建了监听netca--创建新的监听 vi $ORACLE_HOME/net ...

  10. c++/c/java 资源共享群

    Hi,我邀请你加入360云盘文件共享群:c++&c&java, 打开邀请链接:http://qun.yunpan.360.cn/10005202 , 输入邀请码:1357