Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- const string ERROR_NOT_NUMBER = "Ошибка: должно быть число";
- int amax(int* a, int k)
- {
- bool status = true;
- int* b = new int[k];
- for (int i = 0; i < k; i++) {
- b[i] = a[i];
- }
- int max = b[0];
- while (status) {
- max = b[0];
- int index = 0;
- int schet = 1;
- for (int i = 1; i < k; i++) {
- if (b[i] > max) {
- max = b[i];
- index = i;
- }
- if (b[i] == max) {
- schet++;
- }
- }
- if (schet < 2) {
- b[index] = std::numeric_limits<int>::min();
- }
- else {
- status = false;
- }
- }
- return max;
- }
- int main() {
- try {
- int k = 0;
- cin >> k;
- if (!cin) {
- throw ERROR_NOT_NUMBER;
- return -1;
- }
- int* a = new int[k];
- for (int i = 0; i < k; i++) {
- cin >> a[i];
- if (!cin) {
- throw ERROR_NOT_NUMBER;
- return -1;
- }
- }
- cout << amax(a, k) << "\n";
- }
- catch(const char* error){
- cerr << error << "\n";
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement