当前位置:网站首页>【 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);
}
边栏推荐
猜你喜欢
STM32F103实现IAP在线升级应用程序
EndNote使用指南
搭建Tigase进行二次开发
【ASM】字节码操作 MethodVisitor 案例实战 生成对象
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
接口设计
蓄电池建模、分析与优化(Matlab代码实现)
A Practical Guide to Building OWL Ontologies using Protege4 and CO-ODE Tools - Version 1.3 (7.4 Annotation Properties - Annotation Properties)
Sweet alert
Ontology Development Diary 03 - When debugging is in progress
随机推荐
3.List接口与实现类
【ASM】字节码操作 MethodVisitor 案例实战 生成对象
IDEA见过就会爱上的超实用快捷键,一键十行!
从源码分析UUID类的常用方法
MySQL约束关系,你必须要知道的知识点!
Ontology development diary 02 - simple sparql query
2021-04-26QGIS3.10加载天地图影像(地图瓦片)的一种方法
3.List interface and implementation class
【个人学习总结】CRC校验原理及实现
3. Coding method
BlockingQueue理论普
五个不同事物隔离级别,七个事物传播行为
2.Collection接口
2.Collection interface
Tom Morgan | 人生二十一条法则
日期操作比较全面得代码
[Personal study summary] CRC verification principle and implementation
7.FileFilter接口
Ontology development diary 04 - to try to understand some aspects of protege
Go-接口的那些事