Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int N;
- cin >> N;
- vector<int> arr(N); // or int arr[N] = {0};
- // Fill the vector or array
- for(int k = 0; k < N; ++k)
- {
- cin >> arr[k];
- }
- int most_Frequent_num = 0;
- int print_index = 0;
- int counter_most_equal = 0;
- for(int i = 0; i < N; ++i)
- {
- int counter_Frequent_loop = 0;
- for(int j = 0; j < N; ++j)
- {
- if(arr[i] == arr[j])
- {
- counter_Frequent_loop++;
- }
- if(most_Frequent_num < counter_Frequent_loop)
- {
- most_Frequent_num = counter_Frequent_loop;
- counter_most_equal++;
- }
- }
- }
- vector<int> numbers;
- for (int i = 0; i <= N; ++i)
- {
- //2 2 5 5
- int test_counter = 0;
- for(int j = 0; j <= N; ++j)
- {
- //2 =? 2 , 2=?2 , 2=?5 , 2=? 5
- // 0 0 0 1 0 2 0 3
- if(arr[i] == arr[j])
- {
- test_counter++;
- if(counter_most_equal == test_counter)
- {
- print_index = arr[i];
- // cout << print_index << '\n';
- numbers.push_back(print_index);
- }else
- {
- }
- }
- }
- }
- vector<int>::iterator it;
- vector<int>::iterator it2;
- for (it = numbers.begin(); it != numbers.end(); ++it)
- {
- for (it2 = numbers.begin(); it2 != numbers.end(); ++it2)
- {
- if(numbers.at(*it) == numbers.at(*it2))
- {
- it=numbers.erase(it2);
- }
- }
- }
- for (int i = 0; i < numbers.size(); i +=counter_most_equal)
- {
- sort(numbers.begin(), numbers.end());
- cout << numbers.at(i) << ' ';
- }
- // if(counter_most_equal <= 1 )
- // {
- // for (int i = 0; i < numbers.size()-1; i++)
- // {
- // cout << numbers.at(i) << ' ';
- // }
- // ///cout << "No Frequent Number" << '\n';
- // return 2;
- // }else
- // {
- // for (int i = 0; i < numbers.size(); i +=counter_most_equal)
- // {
- // sort(numbers.begin(), numbers.end());
- // cout << numbers.at(i) << ' ';
- // }
- // }
- // cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement