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

     

     

  • 相关阅读:
    谈谈C++新标准带来的属性(Attribute)
    金融数据智能峰会 | 数据规模爆炸性增长,企业如何进行精准决策?云原生数据仓库数据化运营实战分享
    核桃编程:前端可观测性建设之路
    AI和大数据结合,智能运维平台助力流利说提升核心竞争力
    Python静态类型解析工具简介和实践
    盛京剑客系列24:极简估值教程——题记
    Echarts——关系图(人民的名义为例,简化)源码
    UVA10020(最小区间覆盖)
    LA4636积木艺术
    LA4636积木艺术
  • 原文地址:https://www.cnblogs.com/TYH-TYH/p/9377803.html
Copyright © 2011-2022 走看看