-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber01.cpp
More file actions
34 lines (27 loc) · 834 Bytes
/
problemnumber01.cpp
File metadata and controls
34 lines (27 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
using namespace std;
// function return the sum of the numbers that occur only once.
int repeats(vector<int>v) {
int result = 0;
sort(v.begin(), v.end());
for (int num : v) {
if (count(v.begin(),v.end(),num)==1)
{
result += num;
}
}
return result;
}
int main() {
cout << repeats({ 4,5,7,5,4,8 });
return 0;
}
/*In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once.
For example, repeats([4,5,7,5,4,8]) = 15 because only the numbers 7 and 8 occur once, and their sum is 15. Every other number occurs twice.
More examples in the test cases.
Good luck!
If you like this Kata, please try: */