zoukankan      html  css  js  c++  java
  • The flower(寻找出现m次以上,长度为k的子串)

    链接:https://ac.nowcoder.com/acm/contest/3665/B
    来源:牛客网

    题目描述

    Every problem maker has a flower in their heart out of love for ACM. As a famous problem maker, hery also has a flower.
    Hery define string T as flower-string if T appears more than twice in string S and |T| = k. Hery wants you to find how many flower-string in S.

    输入描述:

    The first line contains a string S consist of ’f’, ’l’, ’o’, ’w’, ’e’, ’r’ and an integer k.(1≤∣S∣≤105,1≤k≤100)(1 ≤ |S| ≤ 10^5, 1 ≤ k ≤ 100)(1S105,1k100)

    输出描述:

    Output an integer m in the first line, the number of flower − string in S.
    Next m lines, each line contains a flower-string and the lexicographical order of them should be from small to large

    示例1

    输入

    flowerflowerflower 3

    输出

    4
    flo
    low
    owe
    wer

    利用map储存长为k的字符串,暴力计算即可。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 #include <ctime>
    14 const int INF=0x3f3f3f3f;
    15 typedef long long LL;
    16 const int mod=1e9+7;
    17 const LL MOD=20010905;
    18 const double PI = acos(-1);
    19 const double eps =1e-8;
    20 #define Bug cout<<"---------------------"<<endl
    21 const int maxn=1e5+10;
    22 using namespace std;
    23 
    24 set<string> st;
    25 map<string,int> mp;
    26 
    27 int main()
    28 {
    29     #ifdef DEBUG
    30     freopen("sample.txt","r",stdin);
    31     #endif
    32 //    ios_base::sync_with_stdio(false);
    33 //    cin.tie(NULL);
    34     
    35     string str;
    36     int k;
    37     cin>>str>>k;
    38 
    39     if(k<=str.size())
    40     {
    41         for(int i=0;i<=str.size()-k;i++)
    42         {
    43             string now=str.substr(i,k);
    44             mp[now]++;
    45             if(mp[now]==3) st.insert(now);
    46         }
    47     }
    48 
    49     cout<<st.size()<<endl;
    50     for(set<string>::iterator it=st.begin();it!=st.end();it++)
    51         cout<<*it<<endl;
    52     
    53     return 0;
    54 }

    -

  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/jiamian/p/12216441.html
Copyright © 2011-2022 走看看