Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 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. int h = 1;
  65. while (h < 0 || h > 4) {
  66. cout << "Vyberite chto hoticie uznac :" << endl;
  67. cout << "1) Kolvo raznych vidov u vladilca " << endl;
  68. cout << "2) Vladelcy i kliczki dlia opred vida " << endl;
  69. cout << "3) Skolko vidov s opredelennoj kliczkoj " << endl;
  70. cout << "4) Max i min vozrasty vseh vidov" << endl;
  71. cin >> h;
  72. }
  73. string vid;
  74. string klicz;
  75. int kolvo(0);
  76. bool got(0);
  77. switch (h) {
  78. case(1):
  79. for (auto& it : vladkol) {
  80. int k = it.second.size();
  81. int kolvo(0);
  82. vector<string> st;
  83. bool flag(0);
  84. for (int i = 0; i < k; i++) {
  85. for (int j = 0; j < st.size(); j++) {
  86. if (it.second[i].first == st[j]) {
  87. flag = 1;
  88. break;
  89. }
  90. }
  91. if (flag == 1)
  92. continue;
  93. else {
  94. st.push_back(it.second[i].first);
  95. kolvo++;
  96. }
  97. }
  98. cout << "U vladelca " << it.first << " " << kolvo << " vid(ov) zyvotnych" << endl;
  99. }
  100. break;
  101. case(2):
  102. cout << "Vvedite vid : ";
  103. cin >> vid;
  104. for (auto& it : vladkol) {
  105. int k = it.second.size();
  106. string klicz;
  107. bool flag(0);
  108. vector<string> st;
  109. for (int i = 0; i < k; i++) {
  110. for (int j = 0; j < st.size(); j++) {
  111. if (it.second[i].second == st[j]) {
  112. flag = 1;
  113. break;
  114. }
  115. }
  116. if (flag == 1)
  117. continue;
  118. else {
  119. if (it.second[i].first == vid) {
  120. klicz = it.second[i].second;
  121. st.push_back(klicz);
  122. cout << "U vladelca " << it.first << " pitomec po kliczke " << klicz << endl;
  123. got = 1;
  124. }
  125. }
  126. }
  127. }
  128. if (got == 0)
  129. cout << "Takoj kliczki neizvestno " << endl;
  130. break;
  131. case(3):
  132. cout << "Vvedite kliczku : ";
  133. cin >> klicz;
  134. for (auto& it : vladkol) {
  135. int k = it.second.size();
  136. vector<string> st;
  137. bool flag(0);
  138. for (int i = 0; i < k; i++) {
  139. for (int j = 0; j < st.size(); j++) {
  140. if (it.second[i].first == st[j]) {
  141. flag = 1;
  142. break;
  143. }
  144. }
  145. if (flag == 1)
  146. continue;
  147. else {
  148. if (it.second[i].second == klicz) {
  149. kolvo++;
  150. st.push_back(it.second[i].first);
  151. }
  152. }
  153. }
  154. }
  155. cout << "Kolvo vidov s kliczkoj " << klicz << " ravno " << kolvo;
  156. break;
  157. case(4):
  158. for (auto& it : vozrast) {
  159. cout << "Max vozrast dlia " << it.first << " is " << it.second.second << " , min " << it.second.first << endl;
  160. }
  161. break;
  162. }
  163. fin.close();
  164. return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement