求救

P5734 【深基6.例6】文字处理软件

jiangyunuo @ 2024-11-10 20:29:02

#include<bits/stdc++.h>
using namespace std;
string ch;
int a,b,c;
string str;
int tot,len1,len2;
bool pd(int x){
    for(int i=0;i<len2;i++){
        if(ch[i+x]!=str[i])return 0;
    }
    return 1;
}
int main(){
    int n;
    cin>>n;
    cin>>ch;
    string sh;
    bool z;
    len1=ch.size();
    for(int i=1;i<=n;i++){
        cin>>c;
        if(c==1){
            cin>>str;
            len2=str.size();
            ch+=str;
            cout<<ch<<endl;
            len1+=len2;
        }
        if(c==2){
            cin>>a>>b;
            tot=-1;
            for(int i=a;i<=a+b;i++){
                ch[++tot]=ch[i];
            }
            for(int i=b;i<len1;i++)ch[i]=0;
            cout<<ch<<endl;
            len1=b;
        }
        if(c==3){
            cin>>a>>str;
            len2=str.size();
            for(int i=a;i<len1;i++)sh[i-a]=ch[i];
            for(int i=a;i<a+len2;i++)ch[i]=str[i-a];
            for(int i=len2+a;i<len2+len1;i++)ch[i]=sh[i-len2-a];
            for(int i=0;i<len2+len1;i++)cout<<ch[i];
            cout<<endl;
            len1+=len2;
        }
        if(c==4){
            cin>>str;
            len2=str.size();
            z=0;
            for(int i=0;i<len1;i++){
                if(ch[i]==str[0])if(pd(i)){cout<<i<<endl;z=1;break;}
            }
            if(!z)cout<<-1<<endl;
        }
    }
    return 0;
}

by SQRW @ 2024-11-10 20:43:01

#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int w,q,x,y,l,s;
int main(){
    cin>>q>>a;
    for(int i=1;i<=q;i++){
        cin>>w;
        switch(w){
            case 1:{
                cin>>b;
                a+=b;
                cout<<a<<endl;
                break;
                }
            case 2:{
                cin>>x>>y;
                b=a;
                a="";
                for(int i=x;i<x+y;i++)a+=b[i];
                cout<<a<<endl;
                break;
                    }
                case 3:{
                        cin>>x>>c;
                        b=a;
                        a="";
                        for(int i=0;i<b.size();i++){
                            if(i==x)a+=c;
                            a+=b[i];
                        }
                        cout<<a<<endl;
                            break;
                        }
                case 4:{
                    cin>>b;
                    for(int i=0;i<a.size();i++){
                        s=1;
                        for(int j=0;j<b.size();j++)if(a[i+j]!=b[j])s=0;
                        if(s){
                                cout<<i<<endl;
                                break;}
                    }
                    if(!s)cout<<-1<<endl;
                    break;}}} return 0;
    }

你可以参考一下


by monkeyking_QAQ @ 2024-11-10 20:44:24

@SQRW 哇,杰哥


by jiangyunuo @ 2024-11-10 20:51:56

@SQRW thx


by hetao29190303 @ 2024-11-14 22:27:12

#include<iostream>
using namespace std;
string a;
int main()
{
    int q;
    cin >> q;
    cin >> a;
    int b,x,y;
    string str;
    for(int i=1;i<=q;i++)
    {
        cin >> b;
        if(b==1)
        {
            cin >> str;
            a.insert(a.length(),str);
            cout << a << endl;
        }
        else if(b==2)
        {
            cin >> x >> y;
            a=a.substr(x,y);
            cout << a <<endl;
        }
        else if(b==3)
        {
            cin >> x >> str;
            a.insert(x,str);
            cout << a << endl;
        }
        else
        {
            cin >> str;
            int temp=a.find(str);
            if(temp!=string::npos)
            {
                cout << temp << endl;
            }
            else
            {
                cout << "-1" << endl;
            }
        }
    }
    return 0;
}

强烈建议加入新手测水平


|