fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. vector<int> n;
  7. vector<double> x;
  8. int a, sum2 = 0;
  9. double b, res = 0, sum1 = 0;
  10. while (cin >> a >> b)
  11. {
  12. n.push_back(a);
  13. x.push_back(b);
  14. }
  15. for (int i=0; i < x.size(); i++)
  16. {
  17. sum1 += n[i] * x[i];
  18. sum2 += n[i];
  19. res = sum1 / sum2;
  20. }
  21. cout << res << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 3460KB
stdin
3 -0.5 2 -0.4 1 -0.3 5 32 11 5 20 -1
stdout
4.58095