当前位置:网站首页>长沙学院2022暑假训练赛(一)六级阅读
长沙学院2022暑假训练赛(一)六级阅读
2022-08-09 06:34:00 【未央吖】
D-六级阅读_长沙学院2022暑假训练赛(一) (nowcoder.com)https://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是为了找第一个符合的下标
replace替换
(82条消息) C++ replace() 函数用法_cai_niaocainiao的博客-CSDN博客_c++ replace
边栏推荐
- Introduction and use of BeautifulSoup4
- SIGINT, SIGKILL, SIGTERM signal difference, summary of various signals
- Go lang1.18入门精炼教程——第一章:环境搭建
- 字节跳动面试题之镜像二叉树2020
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
- 语句加锁分析
- e-learning summary
- leetcode 之盛水问题
- Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
- Quectel EC20 4G module dial related
猜你喜欢
随机推荐
mongo+ycsb性能测试及线程数分析
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
The solution that does not work and does not take effect after VScode installs ESlint
VS2019常用快捷键
线程的6种状态
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
Flask failed to create database without error
Use of PlantUML plugin in idea
golang zip aes base64
运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
Integer 线程安全的
代码目录结构
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
.NET高级技术
Likou Brush Question 180
bzoj 5333 [Sdoi2018]荣誉称号
String.toLowerCase(Locale.ROOT)
字节跳动笔试题2020 (抖音电商)
字节跳动面试题之镜像二叉树2020
sql problem solving statement to create a table