Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <unordered_map>
- #include <map>
- using namespace std;
- string id, name, word, input, nameValue;
- int age, countAge=0, startAge, endAge, countName = 0;
- istringstream line;
- unordered_map <string, string> UserName;
- map <string, int> UserAge;
- //funkcia za proverka ime
- void SearchName(string nameValue)
- {
- for (auto it = UserName.begin();it!= UserName.end(); it++)
- {
- if (it->second == nameValue)
- {
- countName++;
- }
- }
- if (countName != 0)
- {
- cout<<countName<<endl;
- }
- else
- {
- cout << "0" << endl;
- }
- countName = 0;
- }
- //proverka vyzrastov diapazon
- //age startAge endAge.
- void Countage(int startAge,int endAge)
- {
- for ( auto it = UserAge.begin();it!= UserAge.end(); it++)
- {
- if ((startAge<=it->second) && (it->second < endAge))
- {
- countAge++;
- }
- }
- if (countAge != 0)
- {
- cout << countAge << endl;
- }
- else
- {
- cout << "0" << endl;
- }
- countAge = 0;
- }
- int main()
- {
- std::ios_base::sync_with_stdio(false); //io optimization
- std::cin.tie(nullptr); //io optimization
- unordered_map<string, string> userName;
- map<string, int> userAge;
- while (getline(cin, input) && input != "end") // faster
- {
- istringstream line(input);
- line >> word;
- if (word == "entry")
- {
- line >> id;
- line >> name;
- line >> age;
- UserName.emplace(make_pair(id, name));
- UserAge.emplace(make_pair(id, age));
- }
- if (word == "name")
- {
- line >> nameValue;
- SearchName(nameValue);
- }
- if (word == "age")
- {
- line >> startAge;
- line >> endAge;
- Countage(startAge,endAge);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement