字符串
exmy
Less is more, and more is less.
展开
-
poj--2752 Seek the Name, Seek the Fame(KMP)
poj 2752题解求串中前缀和后缀相同的子串长度。KMP算法中的 next 数组,next[i] 记录的是以 i 为结束位置的串的 前缀和后缀相同 的最大匹配长度。那么,利用此数组,指针 j 不断回滚,j = next[ next[ … next[j]…]],当 S[j] == S[S.lenght() - 1] 的时候,会有一个长度为 j + 1的串满足条件。#include <iostream原创 2016-04-14 19:23:43 · 392 阅读 · 0 评论 -
PAT--1040. Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given “Is PAT&TAP symmetric?”, the longest symmetric sub-string is “s PAT&TAP s”, hence you must原创 2017-06-07 22:40:29 · 354 阅读 · 0 评论 -
hdoj--2222 Keywords Search(AC自动机)
problem link题解多模匹配。#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cstring>#include <queue>using namespace std;struct Node{ Node* fail; Node* next[26];原创 2017-01-21 21:44:33 · 420 阅读 · 0 评论 -
hihoCoder--1036 Trie图(AC自动机)
problem link题解#include <bits/stdc++.h>using namespace std;const int maxn = 26;const int maxn_node = 500010;struct Node{ Node* next[maxn]; Node* fail; int cnt; Node(){ fail = N原创 2017-01-21 15:04:27 · 315 阅读 · 0 评论 -
leetcode--67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.题解class Solution {public: string addBinary(string a, string b) { string s;原创 2017-01-17 20:42:24 · 317 阅读 · 0 评论 -
leetcode--58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as原创 2017-01-16 14:38:00 · 354 阅读 · 0 评论 -
leetcode--38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2017-01-16 14:16:25 · 286 阅读 · 0 评论 -
leetcode--28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题解class Solution {public: int strStr(string haystack, string needle) {原创 2017-01-15 22:35:51 · 311 阅读 · 0 评论 -
hihoCoder--1039 字符消除
描述 小Hi最近在玩一个字符消除游戏。给定一个只包含大写字母”ABC”的字符串s,消除过程是如下进行的:1)如果s包含长度超过1的由相同字母组成的子串,那么这些子串会被同时消除,余下的子串拼成新的字符串。例如”ABCCBCCCAA”中”CC”,”CCC”和”AA”会被同时消除,余下”AB”和”B”拼成新的字符串”ABB”。2)上述消除会反复一轮一轮进行,直到新的字符串不包含相邻的相同字符为止。例如原创 2017-01-13 21:47:48 · 327 阅读 · 0 评论 -
PAT--1060. Are They Equal(字符串处理)
DescriptionIf a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123*105 with simple chopping. Now given the number of原创 2016-12-09 20:35:56 · 397 阅读 · 0 评论 -
PAT--1093. Count PAT's (25)
DescriptionThe string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th charact原创 2016-12-03 20:51:07 · 372 阅读 · 0 评论 -
UVa--1593 Alignment of Code(string)
UVa 1593题意:输入若干行代码文本,要求各列单词的左边界对齐且尽量靠左。单词之间至少要空一格。Sample Input start: integer; // begins herestop: integer; // ends heres: string;c: char; // tempSample Outputstart: integer; // begins her原创 2016-02-15 14:31:57 · 452 阅读 · 0 评论 -
hdoj--1251 统计难题(Trie树)
hdoj 1251题解Trie树入门第一步。 注:g++一直MLE,请选择c++编译。#include <iostream>#include <string>#include <algorithm>#include <cstdio>#include <fstream>#include <cstring>using namespace std;#define MAXN 26struct原创 2016-04-09 23:17:35 · 482 阅读 · 0 评论 -
hdoj--1075 What Are You Talking About(Trie or map)
hdoj 1075题解map,或者,字典树。#include <iostream>#include <map>#include <string>#include <cctype>#include <cstdio>#include <cstring>using namespace std;//889MS 73424Kmap<string, string> mp;int main(){原创 2016-04-12 21:04:55 · 451 阅读 · 0 评论 -
poj--3461 Oulipo(KMP)
poj 3461题意求串W在串T中出现的次数,可重叠。题解kMP模板。#include <iostream>#include <string>#include <fstream>#include <algorithm>using namespace std;int t;int Next[10001];void kmp_pre(string x){ int i, j; j原创 2016-04-13 11:42:26 · 345 阅读 · 0 评论 -
hdoj--2087 剪花布条
hdoj 2087题解不可重叠的匹配。#include <iostream>#include <algorithm>#include <string>using namespace std;int Next[200];void preKMP(string& s){ int i, j; j = Next[0] = -1; i = 0; while(i < (in原创 2016-04-14 18:36:39 · 541 阅读 · 0 评论 -
PAT--1077. Kuchiguse
The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a preference is called “原创 2017-08-07 23:15:50 · 346 阅读 · 0 评论