zoukankan      html  css  js  c++  java
  • 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;
    }
    


                                                                                                                                      

    每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
  • 相关阅读:
    P3834 【模板】可持久化线段树 (静态主席树)
    P3834 【模板】可持久化线段树 (静态主席树)
    2019 南昌网络赛 I. Max answer
    Linux从入门到精通——系统的进程
    Linux从入门到精通——文件权限
    Linux从入门到精通——命令行使用技巧
    Linux从入门到精通——Linux系统的文件及其管理
    Linux从入门到精通——vim及管理输入输出
    Linux从入门到精通——用户管理
    thiny mission 2021 10 15
  • 原文地址:https://www.cnblogs.com/6bing/p/3931231.html
Copyright © 2011-2022 走看看