29. Дан целочисленный массив размера N. Удалить из массива все минимальные элементы, и вывести размер полученного массива и его содержимое. На с++

5 Сен 2019 в 10:42
400 +1
1
Ответы
1
include include

int main() {
int N;
std::cout << "Enter the size of the array: ";
std::cin >> N;

std::vector<int> arr(N);
std::cout << "Enter the elements of the array: ";
for(int i = 0; i < N; i++) {
std::cin >> arr[i];
}
// Find minimum element in the array
int minElement = arr[0];
for (int i = 1; i < N; i++) {
if (arr[i] < minElement) {
minElement = arr[i];
}
}
// Remove all occurrences of minimum element from the array
std::vector<int> resultArr;
for (int i = 0; i < N; i++) {
if (arr[i] != minElement) {
resultArr.push_back(arr[i]);
}
}
// Output the size of the resulting array
std::cout << "Size of the resulting array: " << resultArr.size() << std::endl;
// Output the elements of the resulting array
std::cout << "Elements of the resulting array: ";
for (int i = 0; i < resultArr.size(); i++) {
std::cout << resultArr[i] << " ";
}
return 0;

}

20 Апр 2024 в 03:54
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир