fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cctype>
  5. using namespace std;
  6.  
  7. void toupper_selectively(string &target, const string &search){
  8. string::size_type pos = 0, search_len = search.size();
  9. while((pos = target.find(search, pos)) != string::npos){
  10. auto begin = target.begin() + pos, end = begin + search_len;
  11. for_each(begin, end, [](char &c){c = toupper(c);});
  12. pos += search_len;
  13. }
  14. }
  15.  
  16. int main() {
  17. string target, search;
  18. getline(cin, target);
  19. getline(cin, search);
  20.  
  21. toupper_selectively(target, search);
  22.  
  23. cout << target << endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 4344KB
stdin
i am hungry
hun
stdout
i am HUNgry