zoukankan      html  css  js  c++  java
  • 河南理工大学新生挑战赛(重现赛) 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; }
  • 相关阅读:
    Java MyBatis 插入数据库返回主键
    FISCO-BCOS平台共识
    分布式一致性协议介绍(Paxos、Raft)
    分布式问题分析
    分布式基础知识
    比特币编译(Ubuntu 16.04)
    比特币源代码分析(1)
    c++中的多线程
    剑指offer中数据结构与算法部分学习
    基础的语法知识汇总
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12257337.html
Copyright © 2011-2022 走看看