题目链接:http://poj.org/problem?id=3096
题意:
定义字符串str,定义D-pair为str[i]和str[i+D+1]组成的两个字符长度的字符串,定义一个unique string是任意两个D-pair互不相同,定义一个surprise string是一个str长度范围内所有的D-pair都是unique
思路:
枚举D的取值,遍历所有的D-pair,用map判重。
代码:
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
string str;
map<string, int> mp;
while(cin>>str && str!="*"){
int len = str.size();
bool flag = true;
for(int i=1; i<=len-2; i++){
mp.clear();
for(int j=0; j<len-i&&flag; j++){
string tmp = "";
tmp += str[j];
tmp += str[j+i];
mp[tmp]++;
if(mp[tmp]!=1) flag = false;
}
}
if(!flag)
cout<< str <<" is NOT surprising."<<endl;
else
cout<< str <<" is surprising."<<endl;
}
return 0;
}