萌新关于洛谷oj输入的疑惑
  • 板块学术版
  • 楼主ypp233
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/7/18 19:01
  • 上次更新2023/11/6 22:52:56
查看原帖
萌新关于洛谷oj输入的疑惑
293637
ypp233楼主2020/7/18 19:01
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main(){
    int q;
    freopen("../input.txt", "r", stdin);
    //在洛谷里去掉这句
    string word;
    cin>>q>>word;
    getchar();
    getchar();
    for(int i=0;i<q;i++){
        string line;
        char mode;
        mode=getchar();
        if(mode == '1'){
            string str;
            cin>>str;
            word+=str;
            cout<<word<<'\n';
        }
        else if(mode == '2'){
            int index,num;
            cin>>index>>num;
            word=word.substr(index,num);
            cout<<word<<'\n';
        }
        else if(mode == '3'){
            string str;
            int index;
            cin>>index>>str;
            word=word.substr(0,index)+str+word.substr(index,word.size());
            cout<<word<<'\n';
        }
        else{
            string str;
            cin>>str;
            if(strstr(word.c_str(),str.c_str())!=NULL)
                cout<<strstr(word.c_str(),str.c_str())-word.c_str()<<'\n';
            else cout<<-1<<'\n';
        }
        getchar();
        getchar();
    }
    return 0;
}

以上这段代码,在clion里,按样例输入保存到input.txt里,输出四个-1 而在洛谷在线IDE和提交题里,这段代码就AC. 希望大家能够解惑

2020/7/18 19:01
加载中...