Branch data Line data Source code
1 : : #include <iostream>
2 : : #include <fstream>
3 : : #include <vector>
4 : : #include <unordered_map>
5 : : #include <numeric>
6 : : using namespace std;
7 : :
8 : 2 : int main() {
9 : 2 : ifstream file("input.txt");
10 [ + + ]: 2 : if (!file) {
11 : 1 : cerr << "Error: Could not open input file." << endl;
12 : 1 : return 1;
13 : : }
14 : :
15 : 1 : vector<int> list1;
16 : 1 : unordered_map<int, int> freq;
17 : :
18 : : int a;
19 : : int b;
20 [ + + ]: 1001 : while (file >> a >> b) {
21 : 1000 : list1.push_back(a);
22 : 1000 : ++freq[b];
23 : : }
24 : :
25 : 1000 : cout << accumulate(list1.begin(), list1.end(), 0, [&freq](int sum, int num) {
26 : 1000 : return sum + num * freq[num];
27 : 1 : })
28 : 1 : << endl;
29 [ + + ]: 3 : }
|