fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5.  
  6.  
  7. std::string common_vowels(std::vector<std::string> const& words) {
  8. std::string vowels = "aeiou";
  9. std::string::iterator last = std::end(vowels);
  10.  
  11. for (auto word : words) {
  12. std::sort(std::begin(word), std::end(word));
  13. last = std::set_intersection(
  14. std::begin(vowels), last
  15. , std::begin(word), std::end(word)
  16. , std::begin(vowels));
  17. }
  18.  
  19. return {std::begin(vowels), last};
  20. }
  21.  
  22.  
  23. int main() {
  24. std::vector<std::string> const words = {"waiidwad", "afaiiwd", "esfiad", "sefasefgi", "siegsa"};
  25.  
  26. std::string const vowels = common_vowels(words);
  27.  
  28. std::cout << vowels << std::endl;
  29. }
  30.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
ai