河南理工大学新生挑战赛(重现赛) B The flower (stl)

题目链接:https://ac.nowcoder.com/acm/contest/3665/B

  题意大概就是给你一串由flower这几个字母组成的字符串,然后让你找长度为k并且出现次数为2次以上(不包括2次)

的子串。

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define endl '\n'
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mst(a) memset(a, 0, sizeof(a))
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const int NIL = -1;
const int maxn = 2e5+10;
map<string, int> mark;
set<string> st, ans;
int main(void){
    ios::sync_with_stdio(false);
    string s;
    int k;
    while(cin >> s >> k) {
        int len = s.length();
        for(int i = 0; i<len-k+1; ++i) {
            string t = s.substr(i, k); //构造长度为k的子串
            st.insert(t); //set去重
            ++mark[t]; //map计数
        }
        for (auto v : st) //c++11 新语法
            if (mark[v] > 2)
                ans.insert(v);
        cout << ans.size() << endl;
        for (auto v : ans)
            cout << v << endl;
        st.clear();
     mark.clear(); ans.clear(); }
return 0; }
原文地址:https://www.cnblogs.com/shuitiangong/p/12257337.html