fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm> // Required for count()
  4. using namespace std;
  5.  
  6. int repeats(vector<int> v) {
  7. int s = 0;
  8. for(auto& num : v) {
  9. if(count(v.begin(), v.end(), num) == 1) s += num;
  10. }
  11. return s;
  12. }
  13.  
  14. int main() {
  15. // Test cases
  16. vector<int> test1 = {4, 5, 7, 5, 4, 8};
  17. vector<int> test2 = {9, 10, 19, 13, 19, 13};
  18.  
  19. cout << repeats(test1) << endl; // Should output 15 (7+8)
  20. cout << repeats(test2) << endl; // Should output 19 (9+10)
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
15
19