JosepRivaille

P90532: Països i províncies (1)

May 7th, 2015
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. struct Provincia {
  7.     string nom;
  8.     string capital;
  9.     int habitants;
  10.     int area;
  11.     double pib;
  12. };
  13.  
  14. struct Pais {
  15.     string nom;
  16.     string capital;
  17.     vector<Provincia> provs;
  18. };
  19.  
  20. typedef vector<Pais> Paisos;
  21.  
  22. double pib(const Paisos& p, char c, double d) {
  23.     int tam_p = p.size();
  24.     double suma_pib = 0;
  25.     for (int i = 0; i < tam_p; ++i) {
  26.         if (p[i].nom[0] == c) {
  27.             int tam_provs = p[i].provs.size();
  28.             for (int j = 0; j < tam_provs; ++j) {
  29.                 double hab = p[i].provs[j].habitants;
  30.                 double area =p[i].provs[j].area;
  31.                 if (hab/area > d) suma_pib += p[i].provs[j].pib;
  32.             }
  33.         }
  34.     }
  35.     return suma_pib;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment