-
Notifications
You must be signed in to change notification settings - Fork 0
/
day0_2
33 lines (30 loc) · 850 Bytes
/
day0_2
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
// In this challenge, we practice calculating a weighted mean. //
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int size, inputValue, inputs;
vector<int> elements;
vector<int> weights;
cin >> size;
for(int i = 0; i < size; i++){
cin >> inputValue;
elements.push_back(inputValue);
}
for(int i = 0; i < size; i++){
cin >> inputValue;
weights.push_back(inputValue);
}
float numerator, denominator;
for(int i = 0; i < size; i++){
numerator += elements[i] * weights[i];
denominator += weights[i];
}
cout << fixed << setprecision(1) << numerator / denominator;
return 0;
}