Advertisement
Guest User

Untitled

a guest
May 14th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <unordered_map>
  4. #include <map>
  5.  
  6. using namespace std;
  7. string id, name, word, input, nameValue;
  8. int age, countAge=0, startAge, endAge, countName = 0;
  9. istringstream line;
  10. unordered_map <string, string> UserName;
  11. map <string, int> UserAge;
  12.  
  13.  
  14. //funkcia za proverka ime
  15. void SearchName(string nameValue)
  16. {
  17.  
  18.   for (auto it = UserName.begin();it!= UserName.end(); it++)
  19.   {
  20.     if (it->second == nameValue)
  21.     {
  22.       countName++;
  23.  
  24.     }
  25.  
  26.   }
  27.  
  28.   if (countName != 0)
  29.   {
  30.     cout<<countName<<endl;
  31.   }
  32.   else
  33.   {
  34.     cout << "0" << endl;
  35.   }
  36.  
  37.   countName = 0;
  38.  
  39. }
  40.  
  41. //proverka vyzrastov diapazon
  42. //age startAge endAge.
  43. void Countage(int startAge,int endAge)
  44. {
  45.  
  46.   for ( auto it = UserAge.begin();it!= UserAge.end(); it++)
  47.   {
  48.     if ((startAge<=it->second) && (it->second < endAge))
  49.     {
  50.       countAge++;
  51.  
  52.     }
  53.   }
  54.   if (countAge != 0)
  55.   {
  56.     cout << countAge << endl;
  57.   }
  58.   else
  59.   {
  60.     cout << "0" << endl;
  61.   }
  62.   countAge = 0;
  63. }
  64.  
  65.  
  66.  
  67.  
  68. int main()
  69. {
  70.   std::ios_base::sync_with_stdio(false); //io optimization
  71.   std::cin.tie(nullptr); //io optimization
  72.  
  73.   unordered_map<string, string> userName;
  74.   map<string, int> userAge;
  75.  
  76.   while (getline(cin, input) && input != "end") // faster
  77.   {
  78.     istringstream line(input);
  79.     line >> word;
  80.     if (word == "entry")
  81.     {
  82.  
  83.       line >> id;
  84.       line >> name;
  85.       line >> age;
  86.  
  87.       UserName.emplace(make_pair(id, name));
  88.  
  89.       UserAge.emplace(make_pair(id, age));
  90.  
  91.     }
  92.  
  93.     if (word == "name")
  94.     {
  95.       line >> nameValue;
  96.       SearchName(nameValue);
  97.     }
  98.  
  99.     if (word == "age")
  100.     {
  101.       line >> startAge;
  102.       line >> endAge;
  103.       Countage(startAge,endAge);
  104.     }
  105.  
  106.  
  107.  
  108.   }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement