Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string str;
  8.     getline(cin, str);
  9.     int first_h_index = 0, last_h_index = 0;
  10.     bool first = true;
  11.     for (int i = 0; i < (int)str.length(); i++)
  12.     {
  13.         if (str[i] == 'h')
  14.         {
  15.             if (first)
  16.             {
  17.                 first = false;
  18.                 first_h_index = i;
  19.             }
  20.             last_h_index = i;
  21.         }
  22.     }
  23.     string new_str = "";
  24.     for (int i = last_h_index; i >= first_h_index; i--)
  25.         new_str += str[i];
  26.     if (first_h_index != 0)
  27.     {
  28.         for (int i = 0; i < first_h_index; i++)
  29.             cout << str[i];
  30.         cout << new_str;
  31.         for (int i = last_h_index + 1; i < (int)str.length(); i++)
  32.             cout << str[i];
  33.     }
  34.     else
  35.     {
  36.         if (last_h_index != (int)str.length())
  37.         {
  38.             cout << new_str;
  39.             for (int i = last_h_index + 1; i < (int)str.length(); i++)
  40.                 cout << str[i];
  41.         }
  42.         else
  43.             cout << new_str;
  44.     }
  45.     cout << endl;
  46.     system("pause");
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement