Files
python/TangDou/LuoGuBook/P5734.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

41 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int n; //n条指令
string s; //原来的字符串
string a; //要追加的字符串
int opt; //操作命令,1:追加,2:截取,3:插入,4:查找
int l; //从第几个开始截取
int cnt; //截取几个字符
int main() {
cin >> n >> s;
while (n--) {
cin >> opt;
switch (opt) {
case 1: //追加
cin >> a;
//s.append(a);
s += a;
cout << s << endl;
break;
case 2://截取
cin >> l >> cnt;
s = s.substr(l, cnt);
cout << s << endl;
break;
case 3: //插入
cin >> l >> a;
s.insert(l, a);
cout << s << endl;
break;
case 4: //查找位置
cin >> a;
auto pos = s.find(a);
if (pos == s.npos) printf("%d\n", -1);
else printf("%d\n", pos);
break;
}
}
return 0;
}