Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include <map>
- #include <sstream>
- #include <set>
- #include <unordered_set>
- #include <unordered_map>
- using namespace std;
- void entryFunction(istringstream& istr,unordered_set<string> &setID,
- unordered_map<string, int>& nameMap,map<int, int>& ageMap)
- {
- string ID;
- string name;
- int age=0;
- istr>>ID;
- if(setID.find(ID)==setID.end())
- {
- setID.insert(ID);
- istr>>name>>age;
- nameMap[name]++;
- ageMap[age]++;
- }
- }
- void nameSearchFunction (istringstream& istr, unordered_map<string, int>& nameMap)
- {
- string name;
- istr>>name;
- cout<<nameMap[name]<<endl;
- }
- void ageSearchFunction (istringstream& istr,map<int, int>& ageMap)
- {
- int fromStart=0;
- int toEnd=0;
- istr>>fromStart>>toEnd;
- int usersCounter=0;
- map<int,int>::iterator startIT=ageMap.find(fromStart);
- map<int,int>::iterator endIT= ageMap.find(toEnd);
- for(; startIT!=endIT; ++startIT)
- {
- usersCounter+=startIT->second;
- }
- cout<<usersCounter<<endl;
- }
- main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(NULL);
- unordered_set<string> setID;
- unordered_map<string, int> nameMap;
- map<int, int> ageMap;
- string command;
- while(true)
- {
- ///Take command
- getline(cin, command);
- istringstream istr (command);
- string keyWord;
- istr>>keyWord;
- ///Do something
- if(keyWord=="entry")
- {
- entryFunction(istr, setID, nameMap, ageMap);
- }else if(keyWord=="name")
- {
- nameSearchFunction (istr, nameMap);
- }else if(keyWord=="age")
- {
- ageSearchFunction (istr, ageMap);
- }else if(keyWord=="end")
- {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement