2 条题解

  • 3
    @ 2024-7-25 14:33:29
    #include <iostream>
    #include <cstring>
    using namespace std;
    
    int main() {
        int n, m, x, y;
        string s, t;
        cin >> n >> s;
        for (int i=0; i<n; ++i) {
            cin >> m;
            if (m == 1) {
                cin >> t;
                s += t;
                cout << s << endl;
            } else if (m == 2) {
                cin >> x >> y;
                s = s.substr(x, y);
                cout << s << endl;
            } else if (m == 3) {
                cin >> x >> t;
                s = s.insert(x, t);
                cout << s << endl;
            } else if (m == 4) {
                cin >> t;
                x = s.find(t);
                cout << x << endl;
            }
        }
        return 0;
    }
    
    
    • 0
      @ 2024-8-10 21:02:14
      #include<bits/stdc++.h>
      using namespace std;
      int n,a;
      string s;//初始文档 
      string b1;//待插入字符串 
      string c1;//裁剪后字符串 
      string a1;//待查找的子串 
      int b,c,d=-1,e,f;
      int main(){
      	cin>>n;
      	cin>>s;
      	for(int i=1;i<=n;i++){
      		cin>>a;
      		if(a==1){
      			cin>>b1;
      			s+=b1;
      			cout<<s<<endl;
      		}
      		else if(a==2){
      			cin>>b>>c;
      			c1=s.substr(b,c);//截取b个起c个字符 
      			s=c1;
      			cout<<s;
      			cout<<endl;
      		}
      		else if(a==3){
      			cin>>f>>b1;
      			s.insert(f,b1);//在文档第b个字符前插入字符串b1 
      			cout<<s<<endl; 
      		}
      		else if(a==4){
      			cin>>a1;
      			if(s.find(a1)<s.size()) cout<<s.find(a1)<<endl;//查找子串在文档中的位置 
      			else cout<<-1<<endl; 
      		}
      	}
      	return 0;
      }
      
      • 1

      信息

      ID
      2022
      时间
      1000ms
      内存
      125MiB
      难度
      3
      标签
      (无)
      递交数
      52
      已通过
      27
      上传者