Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6. #include <cstdio>
  7.  
  8. int main() {
  9. std::vector<std::string> arr;
  10. std::string buffer = "";
  11. int tempI = 0;
  12. int n = 0;
  13.  
  14.  
  15. std::cin >> n;
  16.  
  17. do {
  18. std::getline(std::cin, buffer);
  19. if (tempI == 0 || tempI == n) {
  20. if (buffer.size() > 0) {
  21. arr.push_back(buffer);
  22. }
  23. }
  24. else {
  25. arr.push_back(buffer);
  26. }
  27. tempI++;
  28. } while (tempI != n + 1);
  29.  
  30. std::vector<std::string> countArr;
  31. int max = 0;
  32. int index = 0;
  33. int countElements = 0;
  34.  
  35. for (int i = 0; i < n; i++) {
  36. int count = 0;
  37. for (int j = 0; j < n; j++) {
  38. if (arr[i].compare(arr[j]) == 0) {
  39. count++;
  40. }
  41. }
  42.  
  43. std::string temp = std::to_string(count) + arr[i];
  44.  
  45. bool flag = false;
  46.  
  47. if (countArr.size() == 0) {
  48. countArr.push_back(temp);
  49. }
  50.  
  51. for (int i = 0; i < countArr.size(); i++) {
  52. if (temp.compare(countArr[i]) == 0) {
  53. flag = true;
  54. }
  55. }
  56.  
  57. if (flag == false) {
  58. countArr.push_back(temp);
  59. }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. for (int i = 0; i < countArr.size(); i++) {
  66. int num = stoi(countArr[i].substr(0, 1));
  67. if (num >= max) {
  68. max = num;
  69. index = i;
  70. }
  71. }
  72.  
  73. for (int i = 0; i < countArr.size(); i++) {
  74. if (max == stoi(countArr[i].substr(0, 1))) {
  75. countElements++;
  76. }
  77. }
  78.  
  79. sort(countArr.rbegin(), countArr.rend());
  80.  
  81. std::vector<int> indexesArr;
  82.  
  83. for (int i = 0; i < countElements; i++) {
  84. int tempIndex = 0;
  85. for (int j = 0; j < arr.size(); j++) {
  86. std::string temp = countArr[i].substr(1);
  87. if (temp.compare(arr[j]) == 0) {
  88. tempIndex = j;
  89. }
  90. }
  91. indexesArr.push_back(tempIndex);
  92. }
  93.  
  94. int maximum = 0;
  95. for (int i = 0; i < indexesArr.size(); i++) {
  96. if (indexesArr[i] > maximum) {
  97. maximum = indexesArr[i];
  98. }
  99. }
  100.  
  101.  
  102. int mainIndex = 0;
  103. for (int i = 0; i < countElements; i++) {
  104. if (countArr[i].substr(1) == arr[maximum]) {
  105. mainIndex = i;
  106. }
  107. }
  108. std::cout << countArr[mainIndex].substr(0, 1) << std::endl;
  109. std::cout << arr[maximum];
  110.  
  111.  
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement