fork(1) download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <algorithm>
  6.  
  7. using SetOfWords = std::vector<std::string>;
  8.  
  9. void ShowUserInputWordsMessage(size_t number_of_words) {
  10. std::cout << "Please fill sets with " << number_of_words << " words\n";
  11. }
  12.  
  13. std::vector<std::string> GetFilledSetOfWords(size_t number_of_words) {
  14. ShowUserInputWordsMessage(number_of_words);
  15. std::vector<std::string> words_set(number_of_words);
  16. std::copy_n(std::istream_iterator<std::string>(std::cin), number_of_words,
  17. std::back_inserter(words_set));
  18. return words_set;
  19. }
  20.  
  21. void ShowSet(const SetOfWords &set) {
  22. std::copy(set.begin(), set.end(),
  23. std::ostream_iterator<std::string>(std::cout, " "));
  24. std::cout << '\n';
  25. }
  26.  
  27. void ShowIsPermutationMessage(bool is_permutation) {
  28. std::cout << "is" << (is_permutation ? " " : " not ") << "permutation of\n";
  29. }
  30.  
  31. bool IsPermutation(const SetOfWords &first, const SetOfWords &second) {
  32. return std::is_permutation(first.begin(), first.end(), second.begin());
  33. }
  34.  
  35. void ShowIsPermutationSets(const SetOfWords &first, const SetOfWords &second) {
  36. ShowSet(first);
  37. ShowIsPermutationMessage(IsPermutation(first, second));
  38. ShowSet(second);
  39. }
  40.  
  41. int main() {
  42. const size_t kNumberOfWordsInSet = 12;
  43. ShowIsPermutationSets(GetFilledSetOfWords(kNumberOfWordsInSet),
  44. GetFilledSetOfWords(kNumberOfWordsInSet));
  45. return 0;
  46. }
Success #stdin #stdout 0s 3436KB
stdin
1 2 3 4 5 6 7 8 9 10 11 12
12 11 10 9 8 7 6 5 4 3 2 1
stdout
Please fill sets with 12 words
Please fill sets with 12 words
            12 11 10 9 8 7 6 5 4 3 2 1 
is permutation of
            1 2 3 4 5 6 7 8 9 10 11 12