Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- bool coincidence(int amax[], int Size, int index){
- for (int i = 0; i < Size; i++){
- if (amax[i] == index){
- return true;
- }
- }
- return false;
- }
- int main()
- {
- int ASize = 10;
- int MSize = 5;
- srand(time(0));
- int* arr = new int[ASize];
- for(int i = 0; i < ASize; i++){
- arr[i] = rand() % 50 + 1;
- }
- int amax[MSize];
- for(int i = 0; i < MSize; i++){
- amax[i] = 0;
- }
- //Поиск самых больших элементов с исключением найденных.
- for (int i = 0; i < MSize; i++){
- int thelongerelement = 0;
- int thelongindex = 0;
- //Перебираем массив
- for(int j = 0; j < ASize; j++){
- if (coincidence(amax, ASize, j)){
- continue;
- }
- if(thelongerelement < arr[j]){
- thelongerelement = arr[j];
- thelongindex = j;
- }
- }
- amax[i] = thelongindex;
- }
- //Вывод текущего массива
- printf("array:\n");
- for(int i = 0; i < ASize; i++)
- printf("arr[%d]: %d\n", i, arr[i]);
- //Вывод самых больших элементов.
- printf("\narray max:\n");
- for (int i = 0; i < MSize; i++){
- printf("amax[%d]: %d\n", i, arr[amax[i]]);
- }
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement