Advertisement
Dambosin

adf

May 28th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "pch.h"
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. char toLow(char x);
  7.  
  8. bool isVowel(char x);
  9.  
  10. void addAfterZ(string s);
  11.  
  12. void sort(string *s, int l, int r);
  13.  
  14. void sortStr(string s);
  15.  
  16.  
  17. int main() {
  18.     string s;
  19.     cin >> s;
  20.     addAfterZ(s);
  21.     sortStr(s);
  22.     return 0;
  23. }
  24.  
  25. char toLow(char x) {
  26.     if (int(x) < 97)x += 32;
  27.     return x;
  28. }
  29.  
  30. bool isVowel(char x) {
  31.     toLow(x);
  32.     if ((x == 'e') || (x == 'y') || (x == 'u') || (x == 'i') || (x == 'o') || (x == 'a')) return true;
  33.     return false;
  34. }
  35.  
  36. void addAfterZ(string s) {
  37.     string temp1, temp2;
  38.     for (int i = 0; i < s.length(); i++) {
  39.         if (toLow(s[i]) == 'z') {
  40.             temp1 = string(s, 0, i + 1);
  41.             temp2 = string(s, i + 1, s.length() - i - 1);
  42.             s = temp1 + '!' + temp2;
  43.             i++;
  44.         }
  45.     }
  46.     cout << s << endl;
  47. }
  48.  
  49. void sort(string *s, int l, int r) {
  50.     int i = l;
  51.     int j = r;
  52.     char x = toLow((*s)[(l + r) / 2]);
  53.     do {
  54.         while (toLow((*s)[i]) < x)i++;
  55.         while (toLow((*s)[j]) > x)j--;
  56.         if (i <= j) {
  57.             char temp = (*s)[i];
  58.             (*s)[i] = (*s)[j];
  59.             (*s)[j] = temp;
  60.             i++;
  61.             j--;
  62.         }
  63.     } while (i <= j);
  64.     if (i < r)sort(s, i, r);
  65.     if (l < j)sort(s, l, j);
  66. }
  67.  
  68. void sortStr(string s) {
  69.     string toSort;
  70.     for (int i = 0; i < s.length(); i++)if (!isVowel(s[i]))toSort += s[i];
  71.     sort(&toSort, 0, toSort.length() - 1);
  72.     cout << toSort;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement