HDOJ 2736 Surprising Strings
Surprising Strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 294 Accepted Submission(s): 209
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.
X
EE
AAB
AABA
AABB
BCBABCC
*
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的更多相关文章
- HDU 2736 Surprising Strings
Surprising Strings Time Limit:1000MS Memory Limit:65536KB 64 ...
- hdu 2736 Surprising Strings(类似哈希,字符串处理)
重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...
- [POJ3096]Surprising Strings
[POJ3096]Surprising Strings 试题描述 The D-pairs of a string of letters are the ordered pairs of letters ...
- C - Surprising Strings
C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...
- POJ 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5081 Accepted: 333 ...
- 【字符串题目】poj 3096 Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6193 Accepted: 403 ...
- Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...
- [ACM] POJ 3096 Surprising Strings (map使用)
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5783 Accepted: 379 ...
- POJ 3096:Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6258 Accepted: 407 ...
随机推荐
- QT调用CURL
QProcess *mProcess; QStringList arguments; arguments<<"--disable-epsv" <<" ...
- 8天玩转并行开发——第三天 plinq的使用
原文 8天玩转并行开发——第三天 plinq的使用 相信在.net平台下,我们都玩过linq,是的,linq让我们的程序简洁优美,简直玩的是爱不释手,但是传统的linq只是串行代码,在并行的 年代如果 ...
- android文件下载大小和网络不一致(偏大)
今天在写一个文件下载的程序,在网上搜索了一个抄,用来下载MP3文件. 但是发现下载的MP3文件比原来的文件要大,而且MP3中会有杂音. 在Log中加入日志后发现: 从 网络流中获取的流长度为3000 ...
- Boost::Thread 多线程的基础知识
Boost.Thread可以使用多线程执行可移植C++代码中的共享数据.它提供了一些类和函数来管理线程本身,还有其它一些为了实现在线程之间同步数据或者提供针对特定单个线程的数据拷贝.头文件:#incl ...
- Beauty of Array
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
- 基于visual Studio2013解决C语言竞赛题之1093连接链表
题目 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <math.h> #i ...
- box-sizing:content-box
box-sizing:content-box 规定两个并排的带边框的框:
- 记一个手游app数据文件的破解
出于一些非常猥琐的须要,同一时候自己也想做一些新奇的尝试,周末用了大半天时间破解了某款手游的数据文件. 过程比我预想的要顺利,主要原因还是我们开发者的懈怠.咳咳. 步骤例如以下: 下载安装包,解压,发 ...
- struts2对action中的方法进行输入校验---xml配置方式(3)
上面两篇文章已经介绍了通过编码java代码的方式实现action方法校验,这里我们介绍第二种方式:xml配置文件 首先我们来看一个样例: ValidateAction.java: package co ...
- MFC的消息反射机制
1.消息反射解释: 父窗口将子窗口发给它的通知消息,首先反射回子窗口进行处理(即给子窗口一个机会,让子窗口处理此消息),这样通知消息就有机会能被子窗口自身进行处理. 2.MFC中引入消息反射的原因: ...