Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <fstream>
  4. #include <vector>
  5. #include <string>
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. ifstream fin;
  11. string path1("in.txt");
  12. fin.open(path1);
  13. map<string, vector<pair<string,string>>> vladkol;
  14. map<string, pair<int, int>> vozrast;
  15. string str;
  16. while (getline(fin, str)) {
  17. int age;
  18. string vladel(""), vid(""), klicz(""), ages("");
  19. int n(0);
  20. for (int i = 0; i < str.length(); i++) {
  21. if (str[i] == ',') {
  22. n++;
  23. continue;
  24. }
  25. switch (n) {
  26. case 0:
  27. vladel += str[i];
  28. break;
  29. case 1:
  30. vid += str[i];
  31. break;
  32. case 2:
  33. klicz += str[i];
  34. break;
  35. case 3:
  36. ages += str[i];
  37. break;
  38. }
  39. }
  40. if (klicz == "")
  41. klicz = "undefined_by_user";
  42. age = stoi(ages);
  43. if (vladkol.find(vladel) != vladkol.end()) {
  44. pair<string, string> p(vid,klicz);
  45. vladkol.find(vladel)->second.push_back(p);
  46. }
  47. else {
  48. vector<pair<string,string>> v;
  49. pair<string, string> p(vid, klicz);
  50. v.push_back(p);
  51. vladkol.emplace(vladel, v);
  52. }
  53. if (vozrast.find(vid) != vozrast.end()) {
  54. if (age > vozrast.find(vid)->second.second)
  55. vozrast.find(vid)->second.second = age;
  56. else if (age < vozrast.find(vid)->second.first)
  57. vozrast.find(vid)->second.first = age;
  58. }
  59. else {
  60. pair<int, int> f(age, age);
  61. vozrast.emplace(vid, f);
  62. }
  63. }
  64. link:
  65. cout << "Vyberite chto hoticie uznac :" << endl;
  66. cout << "1) Kolvo raznych vidov u vladilca " << endl;
  67. cout << "2) Vladelcy i kliczki dlia opred vida " << endl;
  68. cout << "3) Skolko vidov s opredelennoj kliczkoj " << endl;
  69. cout << "4) Max i min vozrasty vseh vidov" << endl;
  70. int h;
  71. vector<string> st;
  72. vector<string> st1;
  73. cin >> h;
  74. if (h < 0 || h > 4)
  75. goto link;
  76. string vid;
  77. string klicz;
  78. int kolvo(0);
  79. bool got(0);
  80. switch (h) {
  81. case(1):
  82. for (auto& it : vladkol) {
  83. int k = it.second.size();
  84. int kolvo(0);
  85. vector<string> st;
  86. bool flag(0);
  87. for (int i = 0; i < k; i++) {
  88. for (int j = 0; j < st.size(); j++) {
  89. if (it.second[i].first == st[j]) {
  90. flag = 1;
  91. break;
  92. }
  93. }
  94. if (flag == 1)
  95. continue;
  96. else {
  97. st.push_back(it.second[i].first);
  98. kolvo++;
  99. }
  100. }
  101. cout << "U vladelca " << it.first << " " << kolvo << " vid(ov) zyvotnych" << endl;
  102. }
  103. break;
  104. case(2):
  105. cout << "Vvedite vid : ";
  106. cin >> vid;
  107. for (auto& it : vladkol) {
  108. while (!st.empty())
  109. {
  110. st.pop_back();
  111. }
  112. int k = it.second.size();
  113. string klicz;
  114. bool flag(0);
  115. for (int i = 0; i < k; i++) {
  116. for (int j = 0; j < st.size(); j++) {
  117. if (it.second[i].second == st[j]) {
  118. flag = 1;
  119. break;
  120. }
  121. }
  122. if (flag == 1) {
  123. flag = 0;
  124. continue;
  125. }
  126. else {
  127. if (it.second[i].first == vid) {
  128. klicz = it.second[i].second;
  129. st.push_back(klicz);
  130. cout << "U vladelca " << it.first << " pitomec po kliczke " << klicz << endl;
  131. got = 1;
  132. }
  133. }
  134. flag = 0;
  135. }
  136. }
  137. if (got == 0)
  138. cout << "Takoj kliczki neizvestno " << endl;
  139. break;
  140. case(3):
  141. cout << "Vvedite kliczku : ";
  142. cin >> klicz;
  143. for (auto& it : vladkol) {
  144. int k = it.second.size();
  145. bool flag(0);
  146. for (int i = 0; i < k; i++) {
  147. for (int j = 0; j < st1.size(); j++) {
  148. if (it.second[i].first == st1[j]) {
  149. flag = 1;
  150. break;
  151. }
  152. }
  153. if (flag == 1) {
  154. flag = 0;
  155. continue;
  156. }
  157. else {
  158. if (it.second[i].second == klicz) {
  159. kolvo++;
  160. st1.push_back(it.second[i].first);
  161. }
  162. }
  163. }
  164. }
  165. cout << "Kolvo vidov s kliczkoj " << klicz << " ravno " << kolvo;
  166. break;
  167. case(4):
  168. for (auto& it : vozrast) {
  169. cout << "Max vozrast dlia " << it.first << " is " << it.second.second << " , min " << it.second.first << endl;
  170. }
  171. break;
  172. }
  173. fin.close();
  174. return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement