码农知识堂 - 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

     

  • 相关阅读:
    第5章:性能优化《Nginx实战:从入门到精通》
    服务器内存是怎么样的?
    【C++】STL — string的使用 + 模拟实现
    【.NET】快速入门
    基于MSP430送药小车 ----- 拓展篇【2021年全国电赛(F题)】
    Biomedical knowledge graph-enhanced prompt generation for large language models
    CentOS 7防火墙配置
    面向6G网络的水下光通信系统
    【web开发】6、Django(1)
    ELK介绍以及搭建
  • 原文地址:https://blog.csdn.net/weixin_58183566/article/details/126178244
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号