chiyuwang @ 2024-10-23 10:42:59
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int q;
cin >> q;
string a;
string m;
cin >> a;
for (int i = 1; i <= q; i++) {
int t;
cin >> t;
if (t == 1) {
string s;
cin >> ws;
getline(cin, s);
a += s;
cout << a << endl;
}
if (t == 2) {
int p, o;
cin >> p >> o;
m = a.substr(p, o);
cout << m << endl;
}
if (t == 3) {
int pos2;
cin >> pos2;
string b;
cin >> ws;
getline(cin, b);
m.insert(pos2, b);
cout << m << endl;
}
if (t == 4) {
string k;
cin >> ws;
getline(cin, k);
cout << int(m.find(k)) << endl;
}
}
return 0;
}
by 1357911BCC @ 2024-10-25 20:39:33
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int main() {
cin >> n;
cin >> s;
for(int i = 1;i <= n;i++){
int x;
cin >> x;
if(x == 1){
string t;
cin >> t;
s += t;
cout << s << endl;
}
else if(x == 2){
int x,y;
cin >> x >> y;
s = s.substr(x,y);
cout << s << endl;
}
else if(x == 3){
int x;
string t;
cin >> x >> t;
s = s.substr(0,x) + t + s.substr(x ,s.size());
cout << s << endl;
}
else{
string t;
cin >> t;
if(s.find(t) == string::npos) cout << -1 << endl;
else cout << s.find(t) << endl;
}
}
return 0;
}
这样,自行理解