ACM__字符串
字符串相关题目
P1n9
这个作者很懒,什么都没留下…
展开
-
字符串处理
KMP算法:(求最长公共前缀)最长公共前后缀next数组: a b a a b c a b a -1 -1 0 0 1 -1 0 1 2 先写出next算法(1)next数组的定义: 设模式串T[0,m-1],(长度为m),那么next[i]的值表示是能匹配到的最长前缀长度,也是T[0,i - 1]的后缀 ,如上面的例子,T=abcabd,那么next[5]表示既是abca原创 2017-10-04 18:52:12 · 398 阅读 · 0 评论 -
Codeforces Round #506 (Div. 3) A Many Equal Substrings
地址:http://codeforces.com/contest/1029/problem/AKMP算法求字符串的最小循环节 KMP最小循环节、循环周期: 定理:假设S的长度为len,则S存在最小循环节,循环节的长度L为len-next[len],子串为S[0…len-next[len]-1]。 (1)如果len可以被len - next[len]整除,则表明字符串S可以完全由循环节循环...原创 2018-08-31 21:24:57 · 118 阅读 · 0 评论 -
stringstream用法
stringstream用法:https://blog.csdn.net/liangnimahanwei/article/details/83278977转载 2019-02-10 16:24:26 · 103 阅读 · 0 评论 -
c++的string使用
string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符, 提取连续字符序列(称为子串),以及在字符串中删除和添加。我们将介绍一些主要函数: 1、函数find_first_of()和 find_last_of() 执行简单的模式匹配 例如:在字符串中查找单个字符c。 函数find_first_of() 查找在字符串中第1个出现的字符c,而函数find_last...转载 2018-04-03 21:23:20 · 296 阅读 · 0 评论 -
Censor KMP算法
Censorfrog is now a editor to censor so-called sensitive words (敏感词).She has a long text pp. Her job is relatively simple – just to find the first occurence of sensitive word ww and remove it.frog ...原创 2019-03-03 19:09:10 · 215 阅读 · 0 评论 -
练习赛补题------I - Slot Machines KMP循环节
题意:有一段序列,若是在第k个之后形成循环节,循环节长度为p,问最小的k + p其中k,p分别是多少?利用KMP的next数组来求解循环节,因为是从某个数之后形成循环节,所以需要将输入的序列翻转之后,那么每个位置i + 1 - next[i]的值就是当前位置到最后形成的循环节长度,将n - i - 1(位置) + i + 1 - next[i](循环节长度)取最小值即可;#include<...原创 2019-04-05 16:46:51 · 220 阅读 · 0 评论 -
stringstream进行字符串分割
stringstream 是 C++ 提供的另一个字串型的串流(stream)物件,和之前学过的 iostream、fstream 有类似的操作方式。要使用 stringstream, 必須先加入這一行:#include stringstream 主要是用在將一個字串分割,可以先用 clear( )以及 str( ) 將指定字串設定成一开始的內容,再用 >> 把个別的资料输出,例如...转载 2019-08-30 10:36:11 · 1441 阅读 · 0 评论 -
华为机试---简单字符串分割题
字符串分割题可以使用stringstream的简便方法来做#include<bits/stdc++.h>using namespace std; int main(){ string s; while(getline(cin,s)){ int len = s.size(); for(int i = 0;i < len;...原创 2019-08-30 10:46:48 · 384 阅读 · 0 评论