Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <vector>
  4. #include <queue>
  5. #include <string>
  6. #include <cctype>
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <cmath>
  10. #include <set>
  11. #include <list>
  12. #include <cstdio>
  13. #include <string.h>
  14. #include <algorithm>
  15. #include <map>
  16. #include <stack>
  17.  
  18. using namespace std;
  19.  
  20. class Animal
  21. {
  22. public:
  23. string nume;
  24. int varsta;
  25. Animal(string nume,int varsta)
  26. {
  27. this->nume = nume;
  28. this->varsta = varsta;
  29. }
  30.  
  31.  
  32. };
  33.  
  34. class Animal_final
  35. {
  36. public:
  37. string nume;
  38. string specie;
  39. Animal_final(string nume,string specie)
  40. {
  41. this->nume = nume;
  42. this->specie = specie;
  43. }
  44. };
  45.  
  46. struct Zoo
  47. {
  48. string nume,rasa;
  49. int varsta;
  50. } v[100];
  51.  
  52. int main()
  53. {
  54. vector<Animal> a;
  55. map<string,int> m;
  56. string nume,rasa,comanda;
  57. int n,varsta;
  58. cin>>n;
  59. int k;
  60. for(int i=0; i<n; i++)
  61. {
  62. cin>>nume>>rasa>>varsta;
  63. v[i].rasa = rasa;
  64. v[i].nume = nume;
  65. v[i].varsta = varsta;
  66. m[rasa]++;
  67. }
  68. cin>>comanda;
  69. if(comanda == "count")
  70. {
  71. for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
  72. {
  73. cout<<it->first<<" ("<<it->second<<"): ";
  74. for(int i=0; i<n; i++)
  75. {
  76. if(v[i].rasa == it->first)
  77. {
  78. a.push_back(Animal(v[i].nume,v[i].varsta));
  79. }
  80. }
  81. for(int i=0; i<a.size()-1; i++)
  82. {
  83. for(int j=i+1; j<a.size(); j++)
  84. {
  85. if((a[i].varsta > a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
  86. {
  87. swap(a[i],a[j]);
  88. }
  89. }
  90. }
  91. for(int i=0; i<a.size(); i++)
  92. {
  93. cout<<a[i].nume<<" ";
  94. }
  95. a.clear();
  96. cout<<endl;
  97. }
  98. }
  99. else if(comanda == "endangered")
  100. {
  101. cin>>k;
  102. for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
  103. {
  104. if(it->second == 1)
  105. {
  106. for(int i=0; i<n; i++)
  107. {
  108. if(v[i].rasa == it->first && v[i].varsta >=k)
  109. {
  110. a.push_back(Animal(v[i].nume,v[i].varsta));
  111. }
  112. }
  113. }
  114. }
  115. for(int i=0; i<a.size()-1; i++)
  116. {
  117. for(int j=i+1; j<a.size(); j++)
  118. {
  119. if((a[i].varsta < a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
  120. {
  121. swap(a[i],a[j]);
  122. }
  123. }
  124. }
  125. if(a.size() == 0)
  126. {
  127. cout<<endl;
  128. }
  129. else
  130. {
  131. for(int i=0; i<a.size(); i++)
  132. {
  133. cout<<a[i].nume<<" ";
  134. }
  135. a.clear();
  136. cout<<endl;
  137. }
  138. }
  139. else if(comanda == "search")
  140. {
  141. string specie;
  142. cin>>specie;
  143. for(int i=0; i<n; i++)
  144. {
  145. if(v[i].rasa == specie)
  146. {
  147. a.push_back(Animal(v[i].nume,v[i].varsta));
  148. }
  149. }
  150. for(int i=0; i<a.size()-1; i++)
  151. {
  152. for(int j=i+1; j<a.size(); j++)
  153. {
  154. if(a[i].nume > a[j].nume)
  155. {
  156. swap(a[i],a[j]);
  157. }
  158. }
  159. }
  160. if(a.size() == 0)
  161. {
  162. cout<<"No match found."<<endl;
  163. }
  164. else
  165. {
  166. for(int i=0; i<a.size(); i++)
  167. {
  168. cout<<a[i].nume<<" - "<<a[i].varsta<<endl;
  169. }
  170. a.clear();
  171. }
  172. }
  173. else if(comanda == "show")
  174. {
  175. string specie;
  176. string nume;
  177. vector<Animal_final> s;
  178. for(map<string,int>::iterator it = m.begin(); it!=m.end(); it++)
  179. {
  180. for(int i=0; i<n; i++)
  181. {
  182. if(it->first == v[i].rasa)
  183. {
  184. a.push_back(Animal(v[i].nume,v[i].varsta));
  185. }
  186. }
  187. for(int i=0; i<a.size()-1; i++)
  188. {
  189. for(int j=i+1; j<a.size(); j++)
  190. {
  191. if((a[i].varsta > a[j].varsta) || (a[i].varsta == a[j].varsta && a[i].nume > a[j].nume))
  192. {
  193. swap(a[i],a[j]);
  194. }
  195. }
  196. }
  197. specie = it->first;
  198. nume = a[0].nume;
  199. s.push_back(Animal_final(nume,specie));
  200. a.clear();
  201. }
  202. for(int i=0; i<s.size()-1; i++)
  203. {
  204. for(int j=i+1; j<s.size(); j++)
  205. {
  206. if((s[i].nume > s[j].nume))
  207. {
  208. swap(s[i],s[j]);
  209. }
  210. }
  211. }
  212. for(int i=0; i<s.size(); i++)
  213. {
  214. cout<<s[i].nume.c_str()<<" ("<<s[i].specie.c_str()<<")"<<endl;
  215. }
  216. }
  217. return 0;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement