当前位置:网站首页>05.01 字符串
05.01 字符串
2022-07-13 18:58:00 【zzyzxb】
一:知识点概述



位序:1、2、3…第几个
下标:0、1、2…

字符数组。


C++:<1>string类;<2>c风格














#include<iostream>
#include<string>
using namespace std;
int BF(string s, string t, int pos)
{
int i = pos, j = 1, sum = 0;
int slen = s.length();
int tlen = t.length();
while (i <= slen && j <= tlen)
{
sum++;
if (s[i - 1] == t[j - 1]) //如果相等,则继续比较后面的字符
{
i++;
j++;
}
else
{
i = i - j + 2; //i回退到上一轮开始比较的下一个字符
j = 1; //j回退到第1个字符
}
}
cout << "一共比较了" << sum << "次" << endl;
if (j > tlen) //匹配成功
return i - tlen;
else
return 0;
}
int main()
{
string s, t;
int pos;
cin >> s >> t >> pos;
cout << BF(s, t, pos) << endl;
return 0;
}
边栏推荐
- Redis的持久化机制、过期策略、淘汰策略
- Understanding the application on MySQL
- win11触控板用不了怎么办?win11触控板用不了的解决方法
- 不会真有人觉得聊天机器人难吧——使用BERT加载预训练模型得到中文句子向量
- HCIP第五天实验
- 【深入浅出玩转FPGA8------亚稳态】
- 第三讲:股票买卖 III
- Jerry's right and left channel settings [chapter]
- [I2C (Analog) drive ssd1306 OLED screen of Renesas ra6m4 development board]
- 央行:我国绝大部分中小银行的央行评级处于安全边界内
猜你喜欢

【虹科技术】网络万用表在数据中心的应用
![[today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance](/img/2d/c23a367c9e8e2806ffd5384de273d2.png)
[today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance

不要小看WebSocket!长连接、有状态、双向、全双工都是王炸技能

Lesson 3: shortest distance

华为交换机SEP双半环设计方案及配置详细步骤

Hj8 consolidated statement record hj08

如何报考PMP项目管理认证考试?

VRRP basic configuration

【深入浅出玩转FPGA8------亚稳态】

HCIP第二天笔记
随机推荐
[Go]二、RESTful API介紹和API流程和代碼結構
An XML file example
HCIP第一天笔记
Lesson 3: stock trading III
不会真有人觉得聊天机器人难吧——微调BERT模型得到句子间的相似度
【虹科技术】网络万用表在数据中心的应用
Flutter RenderFlex overflowed by pixels on the bottom键盘弹出警告异常
VRRP basic configuration
Persistence mechanism, expiration strategy and elimination strategy of redis
第三讲:取硬币
This article takes you to understand what tensors are in deep learning, how their operations are, how to understand tensors, and the dimensions of tensors, which are easy to understand
Explain ebpf in simple terms | 7 core issues you need to understand
泰山OFFICE技术讲座:奇怪的Times New Roman字体的高度
Common DOS commands
不要小看WebSocket!长连接、有状态、双向、全双工都是王炸技能
Otacle表查询
HCIP第六天笔记
GPU资源池的虚拟化路径
Linear table concept
二项堆原理与解析