LightOJ 1258 - Making Huge Palindromes
来源:互联网 发布:相同文件查找软件 编辑:程序博客网 时间:2024/04/29 20:15
字符串问题。
#include <iostream>#include <cstring>#include <string>#include <cstdio>using namespace std;const int MAX = 1e6 + 5;int next[MAX];void get_next(string& str, int* next){int lenth = str.size();int k = -1, j = 0;next[0] = -1;while (j != lenth){if (k == -1 || str[j] == str[k]){k++;j++;if (str[j] != str[k])next[j] = k;elsenext[j] = next[k];}elsek = next[k];}}int kmp(string& str, string& p){get_next(p, next);int lenth1 = str.size();int lenth2 = p.size();int i = 0, j = 0;while (i != lenth1 && j != lenth2){if (j == -1 || str[i] == p[j]){++i;++j;}else{j = next[j];}}return lenth1 + lenth2 - j;}int main(){int t, cas = 0;scanf("%d", &t);while (t--){string str1;cin >> str1;string str2(str1.rbegin(), str1.rend());printf("Case %d: %d\n", ++cas, kmp(str1, str2));}return 0;}
0 0
- LightOJ 1258 - Making Huge Palindromes
- LightOJ 1258 Making Huge Palindromes (回文&KMP)
- LIGHTOJ 1258 – MAKING HUGE PALINDROMES 【KMP】
- LightOJ 1258 Making Huge Palindromes (回文&KMP)
- LightOJ 1258 - Making Huge Palindromes【kmp】
- lightoj 1258 - Making Huge Palindromes 【Manacher】
- LightOJ 1258 Making Huge Palindromes (回文&KMP)
- LightOJ 1258 - Making Huge Palindromes (KMP)
- LightOJ 1258 Making Huge Palindromes 【Manacher算法】
- LightOJ 1258 Making Huge Palindromes(manacher算法)
- Lightoj-1258 Making Huge Palindromes(kmp||回文串)
- light oj 1258 - Making Huge Palindromes(KMP)
- light OJ 1258 - Making Huge Palindromes【Manacher】
- Light OJ 1258 - Making Huge Palindromes (KMP 或 Manacher)
- light oj 1258 - Making Huge Palindromes (Manacher 变形)
- Light OJ 1258 Making Huge Palindromes 末尾添加最少字符变回文串
- LIGHT OJ 1258 - Making Huge Palindromes 【包含最后一位字符的最长回文串()】
- LightOJ 1033 - Generating Palindromes
- 结束,亦是开始
- 使用XcodeColors 来显示XCGLogger,进行swift 的logger定制
- 遗传算法Genetic Algorithm
- 设计模式——静态代理模式
- fesco源码解析(一):pool详解
- LightOJ 1258 - Making Huge Palindromes
- char * a, char ** a, char * a[], char a[][], char * a[][], char ** a[][], char * a [][][], and so on
- (二)git 推送到远程仓库
- IOS学习 UIDatePicker 省市区 三联动
- JVM学习笔记(五)之类加载机制
- Tap the BUG 点甲虫 概要设计
- python入门
- HDU 1487高斯消元
- Python实现Enigma密码机