JoSoPu

[Exam] X41648 - Tipus de comarques

Jan 7th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct Poblacio {
  7.     string pob;
  8.     int    alt;
  9.     string com;
  10. };
  11.  
  12. string tipusComarca(const vector<Poblacio> & lpob, const string & comarca) {
  13.     int n=lpob.size();
  14.     bool alt=false;
  15.     bool baix=false;
  16.     for (int i=0;i<n;++i){
  17.         if (lpob[i].com==comarca){
  18.             if (lpob[i].alt>=500)
  19.                 alt=true;
  20.             else
  21.                 baix=true;
  22.         }
  23.     }
  24.     if (alt){
  25.         if (baix)
  26.             return "mixed";
  27.         return "mountain";
  28.     }
  29.     return "seaside";
  30. }
  31.  
  32. vector<Poblacio> llegir_poblacions(int n) {
  33.   vector<Poblacio> lpobl(n);
  34.   for (int i = 0; i < n; ++i) {
  35.     cin >> lpobl[i].pob >> lpobl[i].alt >> lpobl[i].com;
  36.   }
  37.   return lpobl;
  38. }
  39.  
  40. int main() {
  41.     int n;
  42.     cin >> n;
  43.     vector<Poblacio> pobles = llegir_poblacions(n);
  44.     string s;
  45.     while (cin >> s){
  46.         cout << s << ": ";
  47.         cout << tipusComarca(pobles,s) << endl;
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment