60分蒟蒻求调

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

Cybersugari @ 2024-10-19 23:06:58

60分蒟蒻求调 感觉没问题啊,但是前两个测试点错了

#include<iostream>
#include<string>
using namespace std;
int main(){
    int q;
    cin>>q;
    string str;
    cin>>str;
    for(int i=0;i<q;++i){
        int t;
        cin>>t;
        switch(t){
            case 1:{
                string mid;
                cin>>mid;
                str+=mid;
                cout<<str<<endl;
                break;
            }
            case 2:{
                int a,b;
                cin>>a>>b;
                str=str.substr(a,b);
                cout<<str<<endl;
                break;
            }
            case 3:{
                int a;
                string mid;
                cin>>a>>mid;
                str.insert(a,mid);
                cout<<str<<endl;
                break;
            }
            case 4:{
                string mid;
                cin>>mid;
                cout<<(str.find(mid)==string::npos?-1:str.find(mid))<<endl;
                break;
            }
        }
    }
    return 0;
}

by sundingjia @ 2024-10-19 23:26:48

第39行:

cout<<(str.find(mid)==string::npos?-1:str.find(mid))<<endl;

改为:

cout<<int(lg.find(str,0))<<endl;

即可。
@Cybersugari


by sundingjia @ 2024-10-19 23:27:46

修正:改为 cout<<int(str.find(mid,0))<<endl;


|