字符串匹配
来源:互联网 发布:中冶南方自动化 知乎 编辑:程序博客网 时间:2024/06/05 10:18
题目
描述
题目标题:
判断短字符串中的所有字符是否在长字符串中全部出现
详细描述:
接口说明
原型:
boolIsAllCharExist(char* pShortString,char* pLongString);
输入参数:
char* pShortString:短字符串
char* pLongString:长字符串
输入
输入两个字符串。第一个为短字符,第二个为长字符。
输出
返回值:
true - 表示短字符串中所有字符均在长字符串中出现
false- 表示短字符串中有字符在长字符串中没有出现
样例输入
bc abc
样例输出
true
思路
循环判断字符是否出现
代码
#include <iostream>#include <string>using namespace std;bool IsAllCharExist(string &pShortString,string &pLongString){ int bits[256] {0}; bool flag=true; //长字符映射 char* ch=&pLongString[0];//取地址 while((*ch)!='\0') { bits[(int)(*ch)]=1;//标记位置 ch++;//向后移 } //短字符映射 ch=&pShortString[0];//取地址 while((*ch)!='\0') { if(bits[(int)(*ch)]==0) //发现不存在的元素 { flag=false;//设置为False break; } ch++;//向后移 } return flag;}int main(){ string str1,str2; cin>>str1>>str2; //字符串匹配 if(IsAllCharExist(str1,str2)) { cout<<"true"<<endl; } else { cout<<"false"<<endl; } return 0;}
0 0
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配...
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 字符串匹配
- 磁盘扇区、柱面详解
- 买已实名好的手机卡要实名制吗
- Setsockopt()函数用法
- Canvas和Bitmap的关系
- HTTP/2性能更好,但是安全性又如何呢?
- 字符串匹配
- 【完整流程】Linux / Ubuntu 服务器 如何挂载 exfat 格式的 U盘 / 移动硬盘
- 实务︱别再争论工业相机的归类问题了,其实这只需两步!
- 小顶堆数据结构C/C++代码实现
- 关于“Chrome DevTools - 编辑CSS样式”
- 使用CSDN CODE托管代码,Git仓库的SSH公钥与私钥分析
- Spring 与Hibernate 整合
- 谈谈Java:Checked Exception与Runtime Exception 的区别
- 司机而动