您的位置:首页 > 编程语言 > C语言/C++

Sicily 1390. Surprising Strings

2016-01-07 14:37 453 查看
Time Limit: 1 secs, Memory Limit: 32 MB

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

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.

[]~( ̄▽ ̄)~* Just do it!

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
bool sky;
string str, strp;
map <string, int> pro;
///
while (cin >> str && str != "*")
{
sky = false;
///
for (int i = 1; i <= str.size() - 1; i++)
{
pro.clear();
for (int j = 0; i + j < str.size(); j++)
{
strp.clear();
strp += str[j];
strp += str[j + i];
pro[strp]++;
}
for (map<string, int> ::iterator k = pro.begin(); k != pro.end(); k++)
if ((*k).second > 1)
{
sky = true;
break;
}
if (sky)
{
cout << str << " is NOT surprising." << endl;
break;
}
}
///
if (! sky)
cout << str << " is surprising." << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Sicily C++ string