码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 长沙学院2022暑假训练赛(一)六级阅读


    D-六级阅读_长沙学院2022暑假训练赛(一) (nowcoder.com)icon-default.png?t=M666https://ac.nowcoder.com/acm/contest/38762/D链接:登录—专业IT笔试面试备考平台_牛客网
    来源:牛客网
     

    Bruce12138 was preparing for CET-6 recently. He found that the names of the protagonists in many articles were very long, so they were difficult to read and difficult to understand.

    So he decided to change the names of all the protagonists in the article into his own names, so that it would be much more comfortable to read.

    But his operation is a little slow. Please write a program to help him replace the name of the protagonist with his own name.

    输入描述:

    The first line contains a string T(1≤∣T∣≤10)T(1\le|T|\le10)T(1≤∣T∣≤10), indicates the name of the protagonist. Note that all characters in this line are uppercase.
    
    The second line contains a single integer n(1≤n≤50)n(1\le n\le50)n(1≤n≤50), indicates the number of sentences to be replaced.
    
    Then nnn lines follow, each line contains a string S(1≤∣S∣≤103)S(1\le|S|\le10^3)S(1≤∣S∣≤103) without spaces, indicates the sentences to be replaced. All characters except the protagonist's name are lowercase.

    输出描述:

    Output nnn lines, each line contains a string represents the sentence after replacing the name of the protagonist with "Bruce12138" (without quotes).

    示例1

    输入

    复制ZHUYIN 1 ZHUYINhiahiahia

    ZHUYIN
    1
    ZHUYINhiahiahia

    输出

    复制Bruce12138hiahiahia

    Bruce12138hiahiahia

    代码

    1. #include
    2. using namespace std;
    3. string m = "Bruce12138";
    4. int main() {
    5. string s,t;
    6. int n;
    7. cin >> s;
    8. cin >> n;
    9. while (n--) {
    10. cin >> t;
    11. int a = t.find(s);
    12. while (a != -1) {
    13. t = t.replace(a,s.size(), m);
    14. a = t.find(s);
    15. }
    16. cout << t << endl;
    17. }
    18. return 0;
    19. }

    find 和replace的用法

    find是为了找第一个符合的下标

    (82条消息) C++中find函数用法_小白的进阶的博客-CSDN博客_c++字符串find函数

    replace替换

    (82条消息) C++ replace() 函数用法_cai_niaocainiao的博客-CSDN博客_c++ replace

     

  • 相关阅读:
    Hive 剖析
    796 · 开锁
    自动定量包装机机械及控制系统设计(PLC控制)
    基于javaweb+mysql的jsp+servlet学生成绩管理系统(管理员、教师、学生)
    Visual Studio: Arm64EC官方支持来了
    【UE5】创建蓝图
    【活动回顾】ABeam News | 庆祝ABeam德硕与毕博中国战略合作十周年,关系再升级
    wiresharak捕获DNS
    C++语言实现网络爬虫详细代码
    通过源码分析RocketMQ主从复制原理
  • 原文地址:https://blog.csdn.net/weixin_58183566/article/details/126178244
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号