zoukankan      html  css  js  c++  java
  • Codeforces Round #342 (Div. 2) B

    B. War of the Corporations
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.

    This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.

    Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.

    Substring is a continuous subsequence of a string.

    Input

    The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.

    Output

    Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.

    Sample test(s)
    Input
    intellect
    tell
    Output
    1
    Input
    google
    apple
    Output
    0
    Input
    sirisiri
    sir
    Output
    2
    Note

    In the first sample AI's name may be replaced with "int#llect".

    In the second sample Gogol can just keep things as they are.

    In the third sample one of the new possible names of AI may be "s#ris#ri".

    题意: 求母串中有多少子串 (母串中字符只能使用一次)

    比赛的时候傻了  本来可以上一波大分 小涨7分  水笔贴水题

    贴q神代码  %%%

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=100005;
    const int MAXM=35;
    char s[MAXN],t[MAXM];
    int main()
    {
        scanf("%s%s",s,t);
        int n=strlen(s),m=strlen(t);
        int res=0;
        for(int i=0;i+m<=n;i++)
        {
            bool flag=1;
            for(int j=0;j<m;j++)
                if(s[i+j]!=t[j])
                    flag=0;
            if(flag)
            {
                s[i+m-1]='#';
                res++;
            }
        }
        printf("%d
    ",res);
        return 0;
    }
    

      

  • 相关阅读:
    列表、元组、字典、集合类型及其内置方法
    Python数字类型及字符串类型的内置方法 ##
    Python之流程控制
    前端混合
    数据库
    oracle 11g 安装过程
    SQLAlchemy
    pipreqs快速生成python项目所需的依赖
    llinux基本操作
    linux简介
  • 原文地址:https://www.cnblogs.com/hsd-/p/5184945.html
Copyright © 2011-2022 走看看