当前位置:网站首页>长沙学院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
边栏推荐
- APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
- P6阿里机试题之2020 斐波那契数
- Reverse Engineering
- db.sqlite3 has no "as Data Source" workaround
- 单例模式
- Search 1688 product interface by image (item_search_img-search 1688 product by image (Politao interface) code docking tutorial
- Unity Gobang Game Design and Simple AI (2)
- Built-in macros in C language (define log macros)
- Simple Factory Pattern
- .NET高级技术
猜你喜欢
随机推荐
Program Performance Analysis - Complexity Analysis
报错:flask: TypeError: ‘function‘ object is not iterable
C语言实现顺序栈和链队列
单例模式
Import the pycharm environment package into another environment
pdf加密、找回密码
pycharm环境包导入到另外一个环境
抗菌药物丨Toronto Research Chemicals 天冬酰胺D
Redis 2 - 高级
el-table缓存数据
为什么以太网无法接收大于1500字节的数据包?
Quectel EC20 4G module dial related
2022.8.8DAY628
分布式id 生成器实现
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
ZIP压缩包文件删除密码的方法
运放-运算放大器经典应用电路大全-应用电路大全
字节跳动面试题之镜像二叉树2020
变压器的工作原理(图解,原理图讲解,一看就懂)
mmdetection源码解析--ResNet18