当前位置:网站首页>长沙学院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
边栏推荐
- The solution that does not work and does not take effect after VScode installs ESlint
- CMake中INSTALL_RPATH与BUILD_RPATH问题
- CalBioreagents超全Id 蛋白兔单克隆抗体,助力科研
- jvm线程状态
- 中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
- C language implements sequential stack and chain queue
- MongDb的查询方式
- Program Performance Analysis - Complexity Analysis
- Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
猜你喜欢
运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
sql problem solving statement to create a table
字节跳动面试题之镜像二叉树2020
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
The Integer thread safe
IQ Products CMV Brite Turbo试剂盒的原理
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
mongo+ycsb性能测试及线程数分析
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
C语言的内置宏(定义日志宏)
随机推荐
VS2019常用快捷键
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal
Unity Gobang Game Design and Simple AI(3)
Use of PlantUML plugin in idea
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
Singleton DCL (double check the lock) full han mode and the hungry
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
mysql 总结
Explain the wait() function and waitpid() function in C language in detail
After the VB.net program is closed, the background is still connected to SQL
逆向工程
IQ Products CMV Brite Turbo试剂盒的原理
数据库中间件-jdbi
golang xml 处理动态属性
Introduction and use of BeautifulSoup4
中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分
TCP segment of a reassembled PDU
INSTALL_RPATH and BUILD_RPATH problem in CMake
ByteDance Written Exam 2020 (Douyin E-commerce)