zoukankan      html  css  js  c++  java
  • 2017中南大学暑期集训day1 : debug&STL-A

    A - Surprising Strings

    题意就是给你一个字符串,例如ZGBG,有一种称谓叫D-unique

    这个字符串 在D=0时, 有三个子串 ZG GB BG,因为这三个都不同,也就是unique,所以ZGGB是 0-unique;

    同理               D=1时,有两个子串ZB GG也是不同,所以ZGGB是 1-unique;

                          D=2时,只有一个子串ZG,独一无二,所以ZGGB是 2-unique;

    ince these three pairs are all different,Thus ZGBG is surprising.因为这三个都是独一无二的,所以满足题目要求;

    用map建立每个子串与数字的联系来统计,很方便。

     
     
    #include<iostream>//暴力
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    const int mod=100007;
    using namespace std;
    char s[100];
    int ans(){
        int l,d,i,j;
        l=strlen(s);
        if(l<3)
            return 1;
        d=1;
        while(d<l){
            for(i=0;i<l-d;i++){
                for(j=i+1;j<l-d;j++){
                    if(s[i]==s[j]&&s[i+d]==s[j+d])
                        return 0;
                }
            }
            d++;
        }
        return 1;
    }
    int main(){
        while(scanf("%s",s)){
        if(s[0]=='*')
            return 0;
        if(ans())
            printf("%s is surprising.
    ");
        else
            printf("%s is NOT surprising.
    ");
        }
        return 0;
    }
    

      

    #include<iostream>
    #include<string>
    #include<map>
    #include<cstdio>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    const int kMaxn(2007);
    
    int main()
    {
    
        char str[10005],pair[3];
        map<string,int> r;
        while(scanf("%s",str) != EOF)
        {
            if(str[0] == '*')
            break;
            int leap,i,len,j;
            len = strlen(str);
            for(i = 0;i < len;i++)
            {
                leap = 1;
                r.clear();
                for(j = 0;j < len-i-1;j++)
                {
                    pair[0] = str[j];
                    pair[1] = str[j+i+1];
                    pair[2] = '';
                    r[pair]++;
                    if(r[pair] > 1)
                    leap = 0;
                }
                if(leap == 0)
                break;
            }
            if(leap)
            printf("%s is surprising.
    ",str);
            else
            printf("%s is NOT surprising.
    ",str);
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    16进制节码解析
    批注:modbus_tkdefines.py
    <20211019> Win10不明原因丢失任务提示栏里的Wifi以及网络任务提示栏logo
    <20210926>log: 运行5年3个月的NAS硬盘更换
    Huggingface中的BERT模型的使用方法
    list变量和dict变量前面加*号
    Linux服务器登录阿里网盘下载和上传文件的方法
    【IDEA与git集成】
    【为什么要用 @param注解】
    【我的编程习惯与开发插件】
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7233811.html
Copyright © 2011-2022 走看看