Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- string change(string s, string a, int i, int len) {
- s.erase(s.begin() + i, s.begin() + i + len);
- string cash = "";
- for(int j = 0; j < i; j++) cash += s[j];
- for(int j = 0; j < a.length(); j++) cash += a[j];
- for(int j = i; j < s.length(); j++) cash += s[j];
- return cash;
- }
- int main() {
- string inp, outp;
- getline(cin, inp);
- getline(cin, outp);
- ifstream in(inp);
- ofstream out(outp);
- string a, b;
- getline(cin, a);
- getline(cin, b);
- string s;
- while(getline(in, s)) {
- for(int i = 0; i < s.length() - a.length(); i++) {
- bool ok = true;
- for(int j = i; j < a.length()+i; j++)
- if(s[j] != a[j - i]) { ok = false; break; }
- if(ok) s = change(s, b, i, a.length());
- }
- out << s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement