Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <string>
- #include <iostream>
- using namespace std;
- char toLow(char x);
- bool isVowel(char x);
- void addAfterZ(string s);
- void sort(string *s, int l, int r);
- void sortStr(string s);
- int main() {
- string s;
- cin >> s;
- addAfterZ(s);
- sortStr(s);
- return 0;
- }
- char toLow(char x) {
- if (int(x) < 97)x += 32;
- return x;
- }
- bool isVowel(char x) {
- toLow(x);
- if ((x == 'e') || (x == 'y') || (x == 'u') || (x == 'i') || (x == 'o') || (x == 'a')) return true;
- return false;
- }
- void addAfterZ(string s) {
- string temp1, temp2;
- for (int i = 0; i < s.length(); i++) {
- if (toLow(s[i]) == 'z') {
- temp1 = string(s, 0, i + 1);
- temp2 = string(s, i + 1, s.length() - i - 1);
- s = temp1 + '!' + temp2;
- i++;
- }
- }
- cout << s << endl;
- }
- void sort(string *s, int l, int r) {
- int i = l;
- int j = r;
- char x = toLow((*s)[(l + r) / 2]);
- do {
- while (toLow((*s)[i]) < x)i++;
- while (toLow((*s)[j]) > x)j--;
- if (i <= j) {
- char temp = (*s)[i];
- (*s)[i] = (*s)[j];
- (*s)[j] = temp;
- i++;
- j--;
- }
- } while (i <= j);
- if (i < r)sort(s, i, r);
- if (l < j)sort(s, l, j);
- }
- void sortStr(string s) {
- string toSort;
- for (int i = 0; i < s.length(); i++)if (!isVowel(s[i]))toSort += s[i];
- sort(&toSort, 0, toSort.length() - 1);
- cout << toSort;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement