Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. string change(string s, string a, int i, int len) {
  9.     s.erase(s.begin() + i, s.begin() + i + len);
  10.     string cash = "";
  11.     for(int j = 0; j < i; j++) cash += s[j];
  12.     for(int j = 0; j < a.length(); j++) cash += a[j];
  13.     for(int j = i; j < s.length(); j++) cash += s[j];
  14.     return cash;
  15. }
  16.  
  17. int main() {
  18.     string inp, outp;
  19.     getline(cin, inp);
  20.     getline(cin, outp);
  21.     ifstream in(inp);
  22.     ofstream out(outp);
  23.     string a, b;
  24.     getline(cin, a);
  25.     getline(cin, b);
  26.     string s;
  27.     while(getline(in, s)) {
  28.         for(int i = 0; i < s.length() - a.length(); i++) {
  29.             bool ok = true;
  30.             for(int j = i; j < a.length()+i; j++)
  31.                 if(s[j] != a[j - i]) { ok = false; break; }
  32.             if(ok) s = change(s, b, i, a.length());
  33.         }
  34.         out << s;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement