fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. vector<string> split(string line)
  7. {
  8. unsigned int k = 0;
  9. for (unsigned int i = 0; i < line.size(); i++) if (line[i] == ' ') k++;
  10. k++;
  11.  
  12. vector<string> res(k);
  13. string l;
  14.  
  15. unsigned int j = 0;
  16. for (unsigned int i = 0; i < line.size(); i++)
  17. {
  18. if (line[i] == ' ')
  19. {
  20. res[j] = l;
  21. l = "";
  22. j++;
  23. }
  24. else l += line[i];
  25. }
  26. res[j] = l;
  27.  
  28. return res;
  29. }
  30.  
  31. void print(vector<string> a)
  32. {
  33. for (int i = 0; i < a.size(); i++)
  34. {
  35. cout << a[i] << " ";
  36. }
  37. cout << endl;
  38. }
  39.  
  40. int main()
  41. {
  42. ios_base::sync_with_stdio(false);
  43. cin.tie(nullptr);
  44. string line1, line2;
  45.  
  46. getline(cin, line1);
  47. getline(cin, line2);
  48.  
  49. vector<string> t1 = split(line1);
  50. vector<string> t2 = split(line2);
  51. vector<string> m;
  52.  
  53. if (t1.size() == t2.size()) cout << "0\n";
  54. else
  55. {
  56. for (unsigned int i = 0, j = 0; i < t1.size(); i++, j++)
  57. {
  58. if (t1[i] != t2[j])
  59. {
  60. m.push_back(t1[i]);
  61. j--;
  62. }
  63. }
  64.  
  65. cout << m.size() << "\n";
  66. sort(m.begin(), m.end());
  67. for (int i = 0; i < m.size()-1; i++) cout << m[i] << "\n";
  68. cout << m[m.size()-1];
  69. }
  70. }
Success #stdin #stdout 0s 15248KB
stdin
ALA MA KOTA ALE ALA
ALA KOTA
stdout
3
ALA
ALE
MA