洛谷 P5734 【深基6.例6】文字处理软件(字符串STL)

题目链接:https://www.luogu.com.cn/problem/P5734

练习字符串STL操作的很好题目。

AC代码:

 1 #include<iostream>
 2 #include<cmath>
 3 #include<string>
 4 #include<cstdio> 
 5 using namespace std;
 6 int n,a;
 7 string qwq;
 8 string c1;
 9 string b1;
10 int b,c,d=-1,e;
11 int main()
12 {
13     cin>>n;
14     cin>>qwq;
15     for(int i=0;i<n;i++)
16     {
17         cin>>a;
18         if(a==1)
19         {
20             cin>>b1;
21             qwq+=b1;
22             cout<<qwq<<endl;
23         }
24         else if(a==2)
25         {
26             cin>>b>>c;
27             c1=qwq.substr(b,c);
28             qwq=c1;
29             cout<<qwq;
30             cout<<endl;
31         }
32         else if(a==3)
33         {
34             cin>>b>>b1;
35             qwq.insert(b,b1);
36             cout<<qwq<<endl;
37         }
38         else if(a==4)
39         {
40             cin>>b1;
41             if(qwq.find(b1)<qwq.size())
42             cout<<qwq.find(b1)<<endl;
43             else
44             cout<<-1<<endl;
45         }
46     }
47     return 0;
48 }
AC代码
原文地址:https://www.cnblogs.com/New-ljx/p/13263223.html