长沙学院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

代码

#include<bits/stdc++.h>
using namespace std;
string m = "Bruce12138";
int main() {
    string s,t;
    int n;
    cin >> s;
    cin >> n;
    while (n--) {
        cin >> t;
        int a = t.find(s);
        while (a != -1) {
            t = t.replace(a,s.size(), m);
            a = t.find(s);
        }
        cout << t << endl;
    }
    return 0;
}

find 和replace的用法

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

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

replace替换

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未央吖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值