-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodility.cpp
48 lines (39 loc) · 1.43 KB
/
codility.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <algorithm>
#include <numeric>
int solution(std::vector<int>& A, std::vector<int>& B)
{
int counter = 0;
for (int K = 1; K < std::size(A); K++)
{
std::vector<int> A_first = std::vector<int>(A.begin(), A.begin() + K);
std::vector<int> A_second = std::vector<int>(A.begin() + K, A.end());
std::vector<int> B_first = std::vector<int>(B.begin(), B.begin() + K);
std::vector<int> B_second = std::vector<int>(B.begin() + K, B.end());
int A_first_sum = std::accumulate(A_first.begin(), A_first.end(), 0);
int A_second_sum = std::accumulate(A_second.begin(), A_second.end(), 0);
int B_first_sum = std::accumulate(B_first.begin(), B_first.end(), 0);
int B_second_sum = std::accumulate(B_second.begin(), B_second.end(), 0);
if ((A_first_sum == A_second_sum) && (B_first_sum == B_second_sum) && (A_first_sum == B_first_sum))
{
counter++;
}
}
return counter;
}
int main()
{
std::vector<int> A = { 4, -1, 0, 3 };
std::vector<int> B = { -2, 5, 0, 3 };
std::cout << solution(A, B) << std::endl;
// debugging
// int K = 1;
// std::vector<int> A_first = std::vector<int>(A.begin(),A.begin()+K);
// std::vector<int> A_second = std::vector<int>(A.begin()+K,A.end());
// for (int i:A_first)
// {std::cout << i << " ";}
// std::cout << std::endl;
// for (int i:A_second)
// {std::cout << i << " ";}
// std::cout << std::endl;
}