Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <cstring>
- #include <cstdio>
- int main() {
- std::vector<std::string> arr;
- std::string buffer = "";
- int tempI = 0;
- int n = 0;
- std::cin >> n;
- do {
- std::getline(std::cin, buffer);
- if (tempI == 0 || tempI == n) {
- if (buffer.size() > 0) {
- arr.push_back(buffer);
- }
- }
- else {
- arr.push_back(buffer);
- }
- tempI++;
- } while (tempI != n + 1);
- std::vector<std::string> countArr;
- int max = 0;
- int index = 0;
- int countElements = 0;
- for (int i = 0; i < n; i++) {
- int count = 0;
- for (int j = 0; j < n; j++) {
- if (arr[i].compare(arr[j]) == 0) {
- count++;
- }
- }
- std::string temp = std::to_string(count) + arr[i];
- bool flag = false;
- if (countArr.size() == 0) {
- countArr.push_back(temp);
- }
- for (int i = 0; i < countArr.size(); i++) {
- if (temp.compare(countArr[i]) == 0) {
- flag = true;
- }
- }
- if (flag == false) {
- countArr.push_back(temp);
- }
- }
- for (int i = 0; i < countArr.size(); i++) {
- int num = stoi(countArr[i].substr(0, 1));
- if (num >= max) {
- max = num;
- index = i;
- }
- }
- for (int i = 0; i < countArr.size(); i++) {
- if (max == stoi(countArr[i].substr(0, 1))) {
- countElements++;
- }
- }
- sort(countArr.rbegin(), countArr.rend());
- std::vector<int> indexesArr;
- for (int i = 0; i < countElements; i++) {
- int tempIndex = 0;
- for (int j = 0; j < arr.size(); j++) {
- std::string temp = countArr[i].substr(1);
- if (temp.compare(arr[j]) == 0) {
- tempIndex = j;
- }
- }
- indexesArr.push_back(tempIndex);
- }
- int maximum = 0;
- for (int i = 0; i < indexesArr.size(); i++) {
- if (indexesArr[i] > maximum) {
- maximum = indexesArr[i];
- }
- }
- int mainIndex = 0;
- for (int i = 0; i < countElements; i++) {
- if (countArr[i].substr(1) == arr[maximum]) {
- mainIndex = i;
- }
- }
- std::cout << countArr[mainIndex].substr(0, 1) << std::endl;
- std::cout << arr[maximum];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement