HDU 2736 Surprising Strings

                                            Surprising Strings

                                             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                Total Submission(s): 344    Accepted Submission(s): 243


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.


题意:给你一个字符串,判断是不是个surprising 串,举例说明  (其中D-pairs意思为一对字母的距离为D)

例如 :ZGBG  如0-pairs—>(ZG,GB,BG) 当D为0时,符合 surprising 串 的规则。

                             1-paris—>(ZB, GG)             当D为1时,符合 surprising 串的规则。

                             2-paris—>(ZG)                        当D为2时,符合 surprising 串的规则。

此时应该注意,D(max) 应该为   strlen(S串)-  2 ;                                                  

         只有当D取到最大值的时候,所有情况都满足surprising 串的规则,S串才是 一个 surprising 串,否则为 NOT。


这个题是个字符串处理的问题 ,所以总结一下,处理此种问题的思路,因为思路才是最重要的!。

#include<stdio.h>
#include<string>
#include<string.h>
#include<map>
#include<iostream>

using namespace std;

int main()
{
    int i,d, mark = 0;
    char  b[100];
    map<string, bool>flag;
    while(gets(b)!=NULL && b[0]!='*')
    {
        int len = strlen(b);
        mark =0;
        for(d=0; d<=len-2; d++)
        {
            flag.clear();
            for(i=0; i<=len-d-2; i++)
            {
                char a[3]={b[i],b[i+d+1],''};
                if(!flag[a])
                    flag[a] = 1;
                else
                {
                    mark = 1;
                    printf("%s is NOT surprising.
", b);
                    break;
                }
            }
            if(mark)
            {
                break;
            }
        }
        if(!mark)
          printf("%s is surprising.
", b);
    }
    return 0;
}


                                                                                                                                  

每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
原文地址:https://www.cnblogs.com/6bing/p/3931231.html