求助
查看原帖
求助
241659
eiheiheihei楼主2020/5/30 10:50

40分

#include <iostream>
#include <string>
using namespace std;
#define reg register unsigned
string word;
inline void insert(reg a, string str){
    reg len = str.length();
    for (reg i = word.length(); i > a; --i)
        word[i + len - 1] = word[i - 1];
    for (reg i = 0; i < len; ++i)
        word[i + a] = str[i];
}
inline void pick(reg a, reg b){
    string new_word;
    for (reg i = 0; i < b; ++i)
        new_word += word[i + a];
    word = new_word;
}
inline int search(string str){
    reg lenstr = str.length(), lenword = word.length();
    reg char flag;
    for (reg i = 0; i < lenword; ++i){
        flag = true;
        for (reg j = 0; j < lenstr; ++j)
            if (word[i + j] != str[j]){
                flag = false;
                break;
            }
        if (flag)
            return i;
    }
    return -1;
}
int main(){
    int q;
    cin >> q >> word;
    for (reg i = 0; i < q; ++i){
        char select;
        string str;
        reg a,b;
        cin >> select;
        switch (select){
            case '1':
                cin >> str;
                cout << (word += str) << endl;
                break;
            case '2':
                cin >> a >> b;
                pick(a,b);
                cout << word << endl;
                break;
            case '3':
                cin >> a >> str;
                insert(a,str);
                cout << word << endl;
                break;
            case '4':
                cin >> str;
                cout << search(str) << endl;
        }
    }
    return 0;
}
2020/5/30 10:50
加载中...