fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. vector<string> split(string s) {
  9. vector<string> words;
  10. string word = "";
  11. int l = s.length();
  12. for (int i = 0; i < l; ++i) {
  13. if (s[i] != ' ') {
  14. word += s[i];
  15. }
  16. if (s[i] == ' ') {
  17. words.push_back(word);
  18. word = "";
  19. }
  20. }
  21. return words;
  22. }
  23.  
  24.  
  25. vector<string> missingWords(string s, string t) {
  26. vector<string> s1 = split(s);
  27. vector<string> s2 = split(t);
  28. vector<string> returns ;
  29.  
  30. int j=0, i=0;
  31.  
  32. while(i<s1.size()){
  33. while(j<s2.size()){
  34. if(s1[i] == s2[j]){
  35. i++;
  36. j++;
  37. }
  38. if(s1[i] != s2[j]){
  39. returns.push_back(s1[i]);
  40. i++;
  41. }
  42.  
  43. }
  44.  
  45. }
  46.  
  47.  
  48. return returns;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. int main()
  55. {
  56. string s="I am using hackerrank to improve programming";
  57. string s2 = "am hackerrank to improve";
  58.  
  59. vector<string> s4 = missingWords(s,s2);
  60.  
  61. for(int i = 0; i<s4.size() ; i++){
  62. cout << s4[i] << " ";
  63. }
  64.  
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
I using improve