1 条题解

  • 0
    @ 2024-3-11 22:47:02

    字符串函数会用即可

    #include <bits/stdc++.h>
    using namespace std;
    string s,s1;
    char c,x;
    int main(){
    	getline(cin,s);
    	cin>>c;
    	if (c=='D'){
    		cin>>x;
    		int now=s.find(x);
    		if (now==-1){cout<<"Not exist";return 0;}
    		s.erase(now,1);
    		cout<<s;return 0;
    	}else if (c=='I'){
    		cin>>x>>s1;
    		int now1=s.rfind(x);
    		if (now1==-1){cout<<"Not exist";return 0;}
    		s.insert(now1,s1);
    		cout<<s;return 0;
    	}else{
    		cin>>x>>s1;
    		bool flag=false;
    		for (int i=0;i<s.size();i++){
    			if (s[i]==x){s.replace(i,1,s1);flag=true;}
    		}
    		if (!flag){cout<<"Not exist";return 0;}
    		cout<<s;return 0;
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    473
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    36
    已通过
    14
    上传者