当前位置:网站首页>【 size_t is unsigned integer (1 > 10) - > 1.
【 size_t is unsigned integer (1 > 10) - > 1.
2022-08-09 09:58:00 【A rebellious above the waist】
c++中string 的size() 函数返回的类型是size_t
是一个无符号整数
size_t介绍
!!!!!!!!!!
所以就会出现-1 > 10 的情况
因为-1 Look at the unsigned case 就是 ff ff ff ff(补码形式)
今天写kmp遇到的一个问题
还以为是我kmp都写不出来了.
This problem can only blame myself for being too careless.
Please attach the correct code
void nextT(string &t, vector<int> &next,int n)
{
int j = 0, k = -1;
next[0] = -1;
while(j < n-1) {
if(k == -1 || t[j] == t[k]) {
next[++j] = ++k;
} else {
k = next[k];
}
}
}
int KMP(string &s, string &t)
{
int m = s.size();
int n = t.size();
int i = 0, j = 0;
vector<int> next(n);
nextT(t,next,n);
while(i < m && j < n) {
if(j == -1 || s[i] == t[j]) {
++i;
++j;
} else {
j = next[j];
}
}
if(j == n)
return i - j;
return -1;
}
int strStr(string haystack, string needle)
{
return KMP(haystack,needle);
}
边栏推荐
猜你喜欢
随机推荐
缓存击穿,缓存穿透,缓存雪崩的解释和对应的一些解决方案
五个不同事物隔离级别,七个事物传播行为
【个人学习总结】CRC校验原理及实现
MySQL约束关系,你必须要知道的知识点!
4.字符流
.equals==
6.Map接口与实现类
.equals ==
1. The concept of flow
latex中复杂公式换行等号对齐
3.编码方式
基本运算符
[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)
在anaconda环境中配置cuda和cudnn
class object property method class member
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
A Practical Guide to Building OWL Ontologies using Protege4 and CO-ODE Tools - Version 1.3 (7.4 Annotation Properties - Annotation Properties)
基于信号量与环形队列实现读写异步缓存队列
LPP代码及其注释
诡秘番外:在现代









