G
来源:互联网 发布:福建预算软件 编辑:程序博客网 时间:2024/05/15 05:13
以下是几种类型题:
A.类型1:匹配子字符串在母串中第几个位置开始出现。
B.类型2:子串在母串中出现了几次(可以有重复的)。
eg:子串:AZA
母串:AZAZAZA
ans = 3;
C.类型3:母串中最多有几个子串。
D.类型4:需要再补几个字符能构成一个类似手链那样循环相同的。
eg:abca ->2
abcde->5
aaa->0
E.类型5:给出一字符串,找出由2个或2个以上相同的子字符串组成的前缀,输出前缀长度及其相同的子字符串数。
F.类型6:当前最小循环节中字符串的个数(不可以补字符串)。
G.类型7:求最小循环节有几个。
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
For each s you should print the largest n such that s = a^n for some string a.
abcdaaaaababab.
143
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
AC代码:
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>using namespace std;int pext[1000000] = {-5};char s[1000000];int len1;void get_next(char *T,int *next){int k = -1;int j = 0;pext[j] = k;while(j < len1){if((k == -1) || (T[j] == T[k])){k++;j++;pext[j] = k;}else{k = pext[k];}}}int main(){while(1){scanf("%s",s);if(strcmp(s,".") == 0){return 0;}else{int sum = 0;len1 = strlen(s);get_next(s,pext);int z;//最小循环节 z = len1 - pext[len1];if(len1 % z ==0){for(int i=1;i<=len1;i++){if(i%z==0)sum++;}printf("%d\n",sum); }else{printf("1\n");}}}return 0;}
阅读全文
0 0
- G#
- g
- G++
- g
- g
- g
- g
- G
- g++
- g
- G
- g++
- G
- G - 。。。。。。。
- g
- G
- G
- G
- repositoryItemComboBox控件的使用
- permissiongen权限管理混淆处理
- C++中 #ifdef 和#endif的作用
- jQuery 详解(含最新的3.x版本)
- 后台管理UI的选择
- G
- python学习_3
- 概率论第四章-随机变量的数字特征
- 唯快不破:TCP/IP详解--TIME_WAIT状态存在的原因
- 写给 Android 开发者的混淆使用手册
- JAVA8新特性之(函数式接口)
- 安卓使用SoundPool音频池预加载音频,实现多音频,小音频的快速多音轨播放
- HTTP协议状态码详解(HTTP Status Code)
- pytorch加载已训练好的word-embedding