Advertisement
SalmaYasser

Invalid Transactions

Dec 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. vector<string> invalidTransactions(vector<string>& transactions) {
  2.  
  3. unordered_map<string, vector<vector<string>>> name_tr;
  4. unordered_set<string> res;
  5.  
  6. for (auto cur_tr :transactions)
  7. {
  8.  
  9. istringstream ss(cur_tr);
  10. vector<string> s(4, "");
  11.  
  12. int i = 0;
  13.  
  14. while(getline(ss,s[i],',') )
  15. {
  16. i++;
  17. }
  18.  
  19. if(stoi(s[2])>1000) res.insert(cur_tr);
  20.  
  21. for (auto past_tr: name_tr[s[0]])
  22. {
  23.  
  24. if (past_tr[3] != s[3] && abs (stoi(past_tr[1]) - stoi(s[1])) <= 60)
  25. {
  26. res.insert(past_tr[0]+","+past_tr[1]+","+past_tr[2]+","+past_tr[3]);
  27. res.insert(cur_tr);
  28. }
  29. }
  30. name_tr[s[0]].push_back({s[0],s[1],s[2],s[3]});
  31. }
  32. vector<string> r (res.begin(), res.end());
  33. return r;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement