fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <limits>
  5. #include <locale>
  6. #include <sstream>
  7. #include <string>
  8.  
  9. const std::string VOWELS = "AEIOUY"; // assume Y is always a vowel
  10.  
  11. int main()
  12. {
  13. // read the input
  14. std::string input;
  15. while (!(std::cin >> input))
  16. {
  17. std::cout << "Invalid input, try again\n";
  18. std::cin.clear();
  19. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  20. }
  21.  
  22. // erase vowels
  23. input.erase(std::remove_if(input.begin(), input.end(), [&](char c)
  24. {
  25. std::locale loc;
  26. c = std::toupper(c, loc);
  27. return std::find(VOWELS.cbegin(), VOWELS.cend(), c) != VOWELS.cend();
  28. }), input.end());
  29.  
  30. // transform to lowercase
  31. std::transform(input.begin(), input.end(), input.begin(), [](char c)
  32. {
  33. std::locale loc;
  34. return std::tolower(c, loc);
  35. });
  36.  
  37. // add . before every remaining letter
  38. std::ostringstream oss;
  39. std::for_each(input.begin(), input.end(), [&](char c)
  40. {
  41. std::locale loc;
  42. if (std::isalpha(c, loc))
  43. {
  44. oss << ".";
  45. }
  46. oss << c;
  47. });
  48.  
  49. input = oss.str();
  50. std::cout << "Resulting string: " << input << std::endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 3480KB
stdin
abcdefghijklmnopqrstuvwxyz1234567890
stdout
Resulting string:  .b.c.d.f.g.h.j.k.l.m.n.p.q.r.s.t.v.w.x.z1234567890