
牛客网---删除公共字符串
���������������2���������������������������������������������������������������������������1������ ������������������������������ ������������������������������������������������������������������ ��������������������� ������������������������ ������������������������������ ��������������������� ��������������������� ������������������������������������������1���
发布日期:2021-05-10 10:38:51
浏览次数:17
分类:精选文章
本文共 2147 字,大约阅读时间需要 7 分钟。
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������size_t find
���������������������������������������������������������������������������������������������������������������������������������������������������������
���������������
find
���������������������������������������������������������������������������������������������������������������������erase
������������������������������������������������������������������������������������������������������������
#include#include #include using namespace std;int main() { string str1, str2; getline(cin, str1); getline(cin, str2); size_t pos = 0; while (pos <= str2.size()) { size_t found = str1.find(str2[pos], pos); if (found == string::npos) { pos++; continue; } if (found > pos) { str1.erasefound(pos, found - pos); } pos = found + 1; } cout << "���������������������1���" << str1 << endl; return 0;}
���������������
getline
������������������������������str1
���str2
���pos
������������������������������������pos
������������������2������������ - ���������������������
str1.find(str2[pos], pos)
���������������������������str2[pos]
��� - ���������������������������������������������������
found
���������������������������������������
str1.erase(found, found - pos)
���������������������found
������������������������������found - pos
������������������������������pos
���found + 1
���������������������������������������������������������������������2������������������������������������1���������������
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年04月06日 13时00分28秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Flink】Flink 底层RPC框架分析
2021-05-09
MySQL错误日志(Error Log)
2021-05-09
oracle使用DBMS_RANDOM包生成随机数据
2021-05-09
C++高精度模板
2021-05-09
解决:angularjs radio默认选中失效问题
2021-05-09
windows环境下安装zookeeper(仅本地使用)
2021-05-09
缓冲区溢出实例(一)--Windows
2021-05-09
Badboy录制脚本时,提示脚本错误的解决方法
2021-05-09
PHP一句话木马小总结与SQL语句写一句话木马
2021-05-09
关于计数排序
2021-05-09
Python中字符串前添加r ,b, u, f前缀的含义
2021-05-09
Hadoop学习笔记—Yarn
2021-05-09
JSONPath小试牛刀之Snack3
2021-05-09
Jenkins - 部署在Tomcat容器里的Jenkins,提示“反向代理设置有误”
2021-05-09
2017年前端框架、类库、工具大比拼
2021-05-09
wxWidgets源码分析(1) - App启动过程
2021-05-09
wxWidgets源码分析(3) - 消息映射表
2021-05-09
wxWidgets源码分析(5) - 窗口管理
2021-05-09
wxWidgets源码分析(6) - 窗口关闭过程
2021-05-09