Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string str;
- getline(cin, str);
- int first_h_index = 0, last_h_index = 0;
- bool first = true;
- for (int i = 0; i < (int)str.length(); i++)
- {
- if (str[i] == 'h')
- {
- if (first)
- {
- first = false;
- first_h_index = i;
- }
- last_h_index = i;
- }
- }
- string new_str = "";
- for (int i = last_h_index; i >= first_h_index; i--)
- new_str += str[i];
- if (first_h_index != 0)
- {
- for (int i = 0; i < first_h_index; i++)
- cout << str[i];
- cout << new_str;
- for (int i = last_h_index + 1; i < (int)str.length(); i++)
- cout << str[i];
- }
- else
- {
- if (last_h_index != (int)str.length())
- {
- cout << new_str;
- for (int i = last_h_index + 1; i < (int)str.length(); i++)
- cout << str[i];
- }
- else
- cout << new_str;
- }
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement