profil

Napisz program w c++ który pobierze 5 cyfr do tablicy wyswietli największą i uporządkuje od najmniejszej do

największej
5 pkt za rozwiązanie + 3 pkt za najlepsze rozwiązanie - 18.2.2020 (14:23) - przydatność: 75% - głosów: 3
Odpowiedzi
TheKryst4K
18.2.2020 (16:10)
#include
#include
#include
#include
using namespace std;
using table = array;
table sorted(const table &input){
int a = input[0], b = input[1], c = input[2];
if(a > b) swap(a, b);
if(a > c) swap(a, c);
if(b > c) swap(b, c);
return {a, b, c};
}
template
ostream& operator<<(ostream& o, const array& arr){
copy(arr.cbegin(), arr.cend(), ostream_iterator(o, " "));
return o;
}
template
void assert_equal(const T1 &lhs, const T2 &rhs){
if(!(lhs == rhs)){
cout << "Assertion failed!\n";
cout << "lhs: " << lhs << ", rhs: " << rhs << endl;
}
}
int main() {
table expected = {1, 2, 3};
table arg = expected;
do{
cout << "( " << arg << ")\n";
assert_equal(sorted(arg), expected);
}while(next_permutation(begin(arg), end(arg)));
return 0;
}
Przydatne rozwiązanie? Tak Nie
PanBlazejSzerzycielPrawdy
2.3.2020 (21:04)
Tu jest link, bo na ściądze jest słabe formatowanie: https://pastebin.com/FivqXbSK
Przydatne rozwiązanie? Tak Nie
Dodaj zadanie