fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool isVowel( const char ch )
  5. {
  6. return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
  7. }
  8.  
  9. void rotate(char *from, char *to)
  10. {
  11. char c = *to;
  12.  
  13. while (--to >= from)
  14. {
  15. *(to + 1) = *to;
  16. }
  17. *from = c;
  18. }
  19.  
  20. void rearange( char *str )
  21. {
  22.  
  23. char *vowel, *consonant;
  24. vowel = str;
  25. consonant = str;
  26.  
  27. while ( *str )
  28. {
  29. while (*consonant && isVowel(*consonant))
  30. {
  31. consonant++;
  32. }
  33. while (*vowel && !isVowel(*vowel))
  34. {
  35. vowel++;
  36. }
  37.  
  38. rotate (str, consonant);
  39. if (consonant > vowel)
  40. {
  41. vowel++;
  42. }
  43. str++;
  44. rotate (str, vowel);
  45. if (vowel > consonant)
  46. {
  47. consonant++;
  48. }
  49. str++;
  50. consonant++;
  51. vowel++;
  52. }
  53.  
  54. }
  55.  
  56. int main( int argc, char *argv[] )
  57. {
  58.  
  59. string val = "aeiouzwxyzabcdeo";
  60.  
  61. std::cout << val << '\n';
  62. rearange( (char*)val.c_str() );
  63. std::cout << val << '\n';
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 3472KB
stdin
aeiouzwxyzabcdeo
stdout
aeiouzwxyzabcdeo
zawexiyozubacedo