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. EasyUI - NumberBox组件

    效果: html代码: <input type ="text" id ="box"/> JS代码: $(function () { $('#box' ...

  2. WPF Popup 置顶问题

    原文 WPF Popup 置顶问题 问题: 使用wpf的popup,当在popup中弹出MessageBox或者打开对话框的时候,popup总是置顶,并遮住MessageBox或对话框. 解决: 写如 ...

  3. QNX系统-关于delay函数与sleep函数的区别

    QNX是类unix系统.在c语言编程过程中,往往会用到delay或者sleep延时函数.两者之间在使用上有一定的区别!!! delay()是循环等待,该进程还在运行,占用处理器. sleep()不同, ...

  4. MapReduce调度与执行原理之作业初始化

    前言 :本文旨在理清在Hadoop中一个MapReduce作业(Job)在提交到框架后的整个生命周期过程,权作总结和日后参考,如有问题,请不吝赐教.本文不涉及Hadoop的架构设计,如有兴趣请参考相关 ...

  5. 猿取向的规划设计模式 ——GoF《设计模式》阅读摘要(零)

    这个话题是很奇怪,设计模式是引导程序的设计不是模仿什么软件?呃.我的意思是,这是 面"对象"相对的设计模式. 我曾见过有人写<给妻子解释设计模式>,这样的把计算机中的思 ...

  6. Java 多线程 (并发)总结

    一.概念 1. 维基百科解释 进程是什么? http://zh.wikipedia.org/wiki/%E8%BF%9B%E7%A8%8B 线程是什么? http://zh.wikipedia.org ...

  7. poj 1845 POJ 1845 Sumdiv 数学模板

    筛选法+求一个整数的分解+快速模幂运算+递归求计算1+p+p^2+````+p^nPOJ 1845 Sumdiv求A^B的所有约数之和%9901 */#include<stdio.h>#i ...

  8. C. Bits (Codeforces Round #276 (Div. 2) )

    题目大意:给你两个数l,r(l<r),求一个数是大于等于l且小于等于r的数中二进制数的1的个数最多,如果1的个数相同则取最小的那个(翻译渣,请见谅!) 思路:把左区间L化为二进制,再把左区间的二 ...

  9. Data Recovery Advisor(数据恢复顾问)

    Data Recovery Advisor 是11g新特性,是Oracle顾问程序架构的一部分,它会在遇到错误时自动收集有关故障信息.如果主动运行Data Recovery Advisor,通常可以在 ...

  10. VK Cup 2012 Qualification Round 1---C. Cd and pwd commands

    Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard ...