Advertisement
Genarito1234

URI 1254 Tag replacement

Aug 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define db(x) cerr << #x << ': ' << x << endl;
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     string word, newer, ans;
  9.     while (getline(cin, word)){
  10.         stringstream final;
  11.         getline(cin, newer);
  12.         getline(cin, ans);
  13.         bool ok = false, tag = false;
  14.         for (int i = 0; i < ans.length(); i++){
  15.             if (ans[i] == '<'){
  16.                 tag = true;
  17.             }else{
  18.                 if (ans[i] == '>')
  19.                     tag = false;
  20.             }
  21.             if (tolower(ans[i]) == tolower(word[0]) && tag){
  22.                 ok = true;
  23.                 for (int j = i+1, h = 1; h < word.length(); j++, h++){
  24.                     if (tolower(ans[j]) != tolower(word[h])){
  25.                         ok = false;
  26.                         break;
  27.                     }
  28.                 }
  29.                 if (ok){
  30.                     final << newer;
  31.                     i += (word.length() - 1);
  32.                 }else{
  33.                     final << ans[i];
  34.                 }
  35.             }else{
  36.                 final << ans[i];
  37.             }
  38.         }
  39.         cout << final.str() << endl; // remplaza todas las ocurrencias
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement