Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <vector>
- #include <queue>
- #include <string>
- #include <cctype>
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <set>
- #include <list>
- #include <cstdio>
- #include <string.h>
- #include <algorithm>
- #include <map>
- #include <stack>
- using namespace std;
- class Animal
- {
- public:
- string nume;
- int varsta;
- Animal(string nume,int varsta)
- {
- this->nume = nume;
- this->varsta = varsta;
- }
- };
- class Animal_final
- {
- public:
- string nume;
- string specie;
- Animal_final(string nume,string specie)
- {
- this->nume = nume;
- this->specie = specie;
- }
- };
- struct Zoo
- {
- string nume,rasa;
- int varsta;
- } v[100];
- int main()
- {
- vector<Animal> a;
- map<string,int> m;
- string nume,rasa,comanda;
- int n,varsta;
- cin>>n;
- int k;
- for(int i=0; i<n; i++)
- {
- cin>>nume>>rasa>>varsta;
- v[i].rasa = rasa;
- v[i].nume = nume;
- v[i].varsta = varsta;
- m[rasa]++;
- }
- cin>>comanda;
- if(comanda == "count")
- {
- for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
- {
- cout<<it->first<<" ("<<it->second<<"): ";
- for(int i=0; i<n; i++)
- {
- if(v[i].rasa == it->first)
- {
- a.push_back(Animal(v[i].nume,v[i].varsta));
- }
- }
- for(int i=0; i<a.size()-1; i++)
- {
- for(int j=i+1; j<a.size(); j++)
- {
- if((a[i].varsta > a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
- {
- swap(a[i],a[j]);
- }
- }
- }
- for(int i=0; i<a.size(); i++)
- {
- cout<<a[i].nume<<" ";
- }
- a.clear();
- cout<<endl;
- }
- }
- else if(comanda == "endangered")
- {
- cin>>k;
- for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
- {
- if(it->second == 1)
- {
- for(int i=0; i<n; i++)
- {
- if(v[i].rasa == it->first && v[i].varsta >=k)
- {
- a.push_back(Animal(v[i].nume,v[i].varsta));
- }
- }
- }
- }
- for(int i=0; i<a.size()-1; i++)
- {
- for(int j=i+1; j<a.size(); j++)
- {
- if((a[i].varsta < a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
- {
- swap(a[i],a[j]);
- }
- }
- }
- if(a.size() == 0)
- {
- cout<<endl;
- }
- else
- {
- for(int i=0; i<a.size(); i++)
- {
- cout<<a[i].nume<<" ";
- }
- a.clear();
- cout<<endl;
- }
- }
- else if(comanda == "search")
- {
- string specie;
- cin>>specie;
- for(int i=0; i<n; i++)
- {
- if(v[i].rasa == specie)
- {
- a.push_back(Animal(v[i].nume,v[i].varsta));
- }
- }
- for(int i=0; i<a.size()-1; i++)
- {
- for(int j=i+1; j<a.size(); j++)
- {
- if(a[i].nume > a[j].nume)
- {
- swap(a[i],a[j]);
- }
- }
- }
- if(a.size() == 0)
- {
- cout<<"No match found."<<endl;
- }
- else
- {
- for(int i=0; i<a.size(); i++)
- {
- cout<<a[i].nume<<" - "<<a[i].varsta<<endl;
- }
- a.clear();
- }
- }
- else if(comanda == "show")
- {
- string specie;
- string nume;
- vector<Animal_final> s;
- for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
- {
- for(int i=0; i<n; i++)
- {
- if(it->first == v[i].rasa)
- {
- a.push_back(Animal(v[i].nume,v[i].varsta));
- }
- }
- for(int i=0; i<a.size()-1; i++)
- {
- for(int j=i+1; j<a.size(); j++)
- {
- if((a[i].varsta > a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
- {
- swap(a[i],a[j]);
- }
- }
- }
- specie = it->first;
- nume = a[0].nume;
- s.push_back(Animal_final(nume,specie));
- a.clear();
- }
- for(int i=0; i<s.size()-1; i++)
- {
- for(int j=i+1; j<s.size(); j++)
- {
- if((s[i].nume > s[j].nume))
- {
- swap(s[i],s[j]);
- }
- }
- }
- for(int i=0; i<s.size(); i++)
- {
- cout<<s[i].nume.c_str()<<" ("<<s[i].specie.c_str()<<")"<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement