洛谷 P5734 【深基6.例6】文字处理软件
思路
简略的字符串操作,其中字符串查找,s.find()函数,判断是否找到要用if (s.find()!=string::npos)
来判断
代码
/* * @Description: * @Author: 多多 * @Date: 2020-10-25 08:40:40 * @LastEditTime: 2020-10-25 09:00:40 * @LastEditors: 多多 */#include <bits/stdc++.h>using namespace std;int main(){ freopen("./INPUT/P5734.in", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s = ""; cin >> s; while (n--) { int x; cin >> x; if (x == 1) { string ss; cin >> ss; s += ss; cout << s << endl; } else if (x == 2) { int a, b; cin >> a >> b; s = s.substr(a, b); cout << s << endl; } else if (x == 3) { int a; string ss; cin >> a >> ss; s.insert(a, ss); cout << s << endl; } else if (x == 4) { string ss; cin >> ss; if (s.find(ss) != string::npos) { cout << s.find(ss) << endl; } else { cout << -1 << endl; } } } return 0;}