Другие языки программирования и технологии

помогите решить задачу пожалуйста на языке C++

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
bool input(long* box, const size_t buffer, const string& path) {
ifstream ifs(path);
auto n = 0U;
if (ifs.is_open()) {
string line;
getline(ifs, line);
istringstream iss(line);
while (iss >> box[n++]) if (n == buffer) break;
ifs.close();
return true;
}
return false;
}
void output(long* box, const size_t buffer, const string& path) {
ofstream ofs(path);
if (ofs.is_open()) {
for (auto i = 0U; i < buffer; ++i) ofs << box[i] << ' ';
ofs.close();
}
}
int main() {
const auto inp("input.txt"s);
const auto out("output.txt"s);
const auto buffer = 5U;
long box[buffer];
if (input(box, buffer, inp)) {
auto max = *max_element(begin(box), end(box));
for_each(begin(box), end(box), [max](long& value) { value -= max; });
output(box, buffer, out);
}
}
Александр Барабанов
Александр Барабанов
75 910
Лучший ответ
Александр Барабанов for_each(begin(box), end(box), [max](long& value) { value = max - value; });
#include <iostream>

template<typename... Args>
int max(int a, Args... args);
int max(int a);

int main(){
using namespace std;

int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;

int m = max(a, b, c, d, e);
a=m-a;b=m-b;c=m-c;d=m-d;e=m-e;

cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e;

return 0;
}

template<typename... Args>
int max(int a, Args... args){
int _max = max(args...);
return _max > a ? _max : a;
}

int max(int a){
return a;
}
#include
#include
using namespace std ;
int main(int argc, const char * argv[]) {
fstream f ; int arr[5] = {} ;
f.open("input.txt", ios::in) ;
for (int i = 0 ; i < 5 ; i++ ) {
f >> arr[i] ;
}
int max = arr[0] ;
f.close() ;
f.open("output.txt", ios::out) ;
for (int i = 0; i < 5 ; i++) {
if (arr[i] > max) { max = arr[i];
}
} for (int i = 0 ; i < 5 ; i++ )
{ f << max - arr[i] << " " ;
}
f.close() ;
return 0;
}