zoukankan      html  css  js  c++  java
  • [水] POJ 3096

    Surprising Strings
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 7659   Accepted: 4878

    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.

    Source

    [Submit]   [Go Back]   [Status]   [Discuss]

    大暴力。。

     1 #include <cstdlib>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 #include<iostream>
     6 #include <cmath>
     7 #include<string>
     8 #define ll long long 
     9 #define dscan(a) scanf("%d",&a)
    10 #define mem(a,b) memset(a,b,sizeof a)
    11 using namespace std;
    12 #define MAXL 1105
    13 #define maxn 1000005
    14 int main()
    15 {
    16     string s;
    17     string ss[100];
    18     while(cin>>s&&s!="*")
    19     {
    20         int l=s.length();
    21         int flag;
    22         if(l<=2) {cout<<s<<" is surprising."<<endl;continue;}
    23         for(int i=0;i<l-2;++i)
    24         {
    25             for(int j=0;j<100;++j) ss[i]="";
    26             int cnt=0;
    27             flag=1;
    28             for(int j=0;j<=l-i-2;++j)
    29             {
    30                 ss[cnt]=s[j]; ss[cnt++]+=s[j+i+1];
    31                 for(int k=0;k<cnt-1;++k) {
    32                     if(ss[k]==ss[cnt-1]) {
    33                         flag=0;break;
    34                     }
    35                 }
    36                 if(!flag) break;
    37             }
    38             if(!flag) break;
    39         }
    40         if(flag) cout<<s<<" is surprising."<<endl;
    41         else cout<<s<<" is NOT surprising."<<endl;
    42     }
    43 }
    View Code

     

     

  • 相关阅读:
    nuxt使用pdfjs-dist插件实现pdf预览
    package.json详细介绍
    encodeURI()和encodeURIComponent() 区别
    前端预览pdf——文件流
    fatal: unable to access 'https://github.com/xxxxx/xxxx.git/': Failed to connect to github.com port 443: Timed out
    vue分隔输入验证码
    Vue简单实现滚动到底部加载数据
    nuxt pdf在线预览
    Eclipse入门-HelloWorld
    多任务学习算法综述
  • 原文地址:https://www.cnblogs.com/TYH-TYH/p/9377803.html
Copyright © 2011-2022 走看看