fork download
  1. #include <vector>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. vector<string> function(vector<string> sequences, vector<string> second_sequences)
  10. {
  11. // sort the sequences
  12. sort(sequences.begin(), sequences.end());
  13. sort(second_sequences.begin(), second_sequences.end());
  14. vector<string> samestrings;
  15. vector<string> diffstrings;
  16.  
  17. // get the strings that are the same
  18. set_intersection(sequences.begin(), sequences.end(), second_sequences.begin(), second_sequences.end(), std::back_inserter(samestrings));
  19.  
  20. // get the strings that are mismatched
  21. set_symmetric_difference(sequences.begin(), sequences.end(), second_sequences.begin(), second_sequences.end(), std::back_inserter(diffstrings));
  22.  
  23. // output the results
  24. cout << "Same strings:" << "\n";
  25. copy(samestrings.begin(), samestrings.end(), ostream_iterator<string>(cout, " "));
  26. cout << "\nMismatch strings:" << "\n";
  27. copy(diffstrings.begin(), diffstrings.end(), ostream_iterator<string>(cout, " "));
  28. return diffstrings;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. const char *p1[] = {"abc", "123", "456", "diff", "same"};
  35. const char *p2[] = {"123", "diff2", "456", "same", "abc"};
  36. vector<string> s1(p1, p1 + 5);
  37. vector<string> s2(p2, p2 + 5);
  38. function(s1, s2);
  39. }
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
Same strings:
123 456 abc same 
Mismatch strings:
diff diff2