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. Android异步载入全解析之使用多线程

    异步载入之使用多线程 初次尝试 异步.异步,事实上说白了就是多任务处理.也就是多线程执行.多线程那就会有各种问题,我们一步步来看.首先.我们创建一个class--ImageLoaderWithoutC ...

  2. shell程序设计(转)

    1.shell脚本的基本概念: (1)Shell执行的是称为shell程序,这些程序通常被称为脚本. (2)Shell是一个用户和系统间接口的程序,它允许用户向操作系统输入需要执行的命令. (3)sh ...

  3. mongdb修改密码

    正确做法,利用db.changeUserPassword > db.changeUserPassword('tank2','test');

  4. Boost::asio io_service 实现分析

    io_service的作用 io_servie 实现了一个任务队列,这里的任务就是void(void)的函数.Io_servie最常用的两个接口是post和run,post向任务队列中投递任务,run ...

  5. 1.1.2-学习Opencv与MFC混合编程之---画图工具 画直线 画圆 画矩形

    源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961685 画图工具 1.     画直线 Ø  增加‘直线’菜单项,建立类向导: Ø  对CXX ...

  6. Ubuntu 14.04LTS Gnome GUI初体验及163更新源配制

    Ubuntu 14.04 LTS于前天(2014.4.17)公布, 我今天将我的系统升级到最新, 体验了下最新的UI系统. 我选择了Ubuntu Gnome 的GUI界面.我曾经的系统是12.04lt ...

  7. 解决Java compiler level does not match the version of the installed Java project facet.问题

    其实之前遇到过Java compiler level does not match the version of the installed Java project facet.这个问题,因为当时没 ...

  8. [课堂实践与项目]IOS优先级的计算器

    这个计算器主要是使用数组进行实现的.虽然没有使用前缀后缀表达式,但是是一种方法o. .h文件 // // LCViewController.h // 具有优先级的calculator // // Cr ...

  9. Android开源框架AsyncHttpClient (android-async-http)使用

    android-async-http 开源框架可以使我们轻松地获取网络数据或者向服务器发送数据,最关键的是,它是异步框架,在底层使用线程池处理并发请求,效率很高,使用又特别简单. 以往我们在安卓上做项 ...

  10. Windows 7如何建立一个FTP的快捷方式

    原来,使用Windows XP的时候,在IE6的地址栏里输入FTP服务器的地址,就可以打开一个资源管理器的界面来管理文件.但是,随着IE的版本的提升或是装了Windows 7,原来的这种方法就不能用了 ...