C/C++

Программирование на C++/

Подскажите пожалуйста с задачей.
В файле "input.txt" находится последовательность чисел. Требуется считать их и вывести в файл "output.txt" все числа в том же порядке, кроме одного минимального и одного максимального (т.е. ровно на два числа меньше, чем было введено).
я написал

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
ifstream fin{"input.txt"};
int n=0;
fin >> n;
double* a = new double[n];
for(int i=0; i<n; i++){
fin >> a[i];}
double max;
double min;
max=a[0];
min=a[0];
for (int j = 0; j < n; j++)
{
if (max < a[j])
{
max = a[j];

}
if (min > a[j])
{
min = a[j];

}
}
for (int i=0; i<n; i++)
{
if (a[i]!=min && a[i]!=max) cout<<a[i]<<" ";
}


}


Если все числа разные, то работает, но мне нужно, если в файле 2 максимального или минимального значения, то выводить хотя бы одно из них, то есть например в файле: 2.5 7.3 7.3 1.1 0.5 6.9. Выводится должно: 2.5 7.3 1.1 6.9
Sahib Hebibullayev
Sahib Hebibullayev
758
 #include  
#include
#include
#include
#include
using namespace std;
int main() {
ifstream inp("input.txt");
if (!inp.is_open()) exit(0);
vector box;
int value;
while (inp >> value) box.push_back(value);
inp.close();
auto [pmin, pmax] = minmax_element(box.begin(), box.end());
stringstream ss;
for (auto it = box.begin(); it != box.end(); ++it) {
if (it != pmin && it != pmax) ss
Suren Grigoryan
Suren Grigoryan
65 779
Лучший ответ
Игорь Сгибнев
Игорь Сгибнев
53 016
Sahib Hebibullayev к сожалению, другие библиотеки использовать нельзя, по условию
 #include  
#include
#include
#include
#include
using namespace std;

void load(const string& path, vector& arr)
{
ifstream inp(path);
if (!inp.is_open()) { cerr
Русик .
Русик .
51 416
 #include 
#include
using namespace std;

int main()
{
// Open the input file
ifstream fin{"input.txt"};

// Read the size of the array
int n = 0;
fin >> n;

// Allocate an array to store the numbers
double* a = new double[n];

// Read the numbers into the array
for(int i=0; i> a[i];
}

// Find the indices of the minimum and maximum values
int min_index = 0;
int max_index = 0;
for (int j = 1; j < n; j++)
{
if (a[j] < a[min_index])
{
min_index = j;
}
if (a[j] > a[max_index])
{
max_index = j;
}
}

// Open the output file
ofstream fout{"output.txt"};

// Print all the numbers except the minimum and maximum values
for (int i=0; i
Жека Невров
Жека Невров
1 346
Жека Невров Похожая программа, коменты не поленился, написал, должна робить
Sahib Hebibullayev Круто, спасибо большое!