c++,40分,求助

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

zhouhang20121018 @ 2025-01-09 20:37:09

include<bits/stdc++.h>

using namespace std; char s[1010],c[1010],v[1010],x[1010]; int q,n,a,b,d; int main(){ cin>>q>>s; while(q--){ cin>>n; if(n==1){ cin>>c; strcat(s,c); strcpy(c,v); cout<<s<<"\n"; }else if(n==2){ cin>>a>>b; for(int i=a;i<=a+b;i++){ c[d]=s[i]; d++; } cout<<c<<"\n"; strcpy(s,c); strcpy(c,v); d=0; }else if(n==3){ cin>>a>>c; for(int i=a;i<=strlen(s)+1;i++){ x[d]=s[i]; d++; s[i]=v[i]; } strcat(s,c); strcat(s,x); cout<<s<<"\n"; strcpy(c,v); }else if(n==4){ cin>>c; if(strstr(s,c)){ cout<<strlen(s)-strlen(strstr(s,c))<<"\n"; } else cout<<-1<<"\n"; strcpy(c,v) } } return 0; }

#include<bits/stdc++.h>
using namespace std;
char s[1010],c[1010],v[1010],x[1010];
int q,n,a,b,d;
int main(){
    cin>>q>>s;
    while(q--){
        cin>>n;
        if(n==1){
            cin>>c;
            strcat(s,c);
            strcpy(c,v);
            cout<<s<<"\n";
        }else if(n==2){
            cin>>a>>b;
            for(int i=a;i<=a+b;i++){
                c[d]=s[i];
                d++;
            }
            cout<<c<<"\n";
            strcpy(s,c);
            strcpy(c,v);
            d=0;
        }else if(n==3){
            cin>>a>>c;
            for(int i=a;i<=strlen(s)+1;i++){
                x[d]=s[i];
                d++;
                s[i]=v[i];
            }
            strcat(s,c);
            strcat(s,x);
            cout<<s<<"\n";
            strcpy(c,v);
        }else if(n==4){
            cin>>c;
            if(strstr(s,c)){
                cout<<strlen(s)-strlen(strstr(s,c))<<"\n";
            }
            else cout<<-1<<"\n";
            strcpy(c,v)
        }
    }
    return 0;
}

|