#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
struct PifaThree
{
int a;
int b;
int c;
PifaThree()
a = 0;
b = 0;
c = 0;
}
PifaThree(int a_, int b_, int c_) : a(a_), b(b_), c(c_)
~PifaThree() {}
void show()
std::cout << a << "^2 = " << b << "^2 + " << c << "^2";
};
int main()
std::vector<int> arr;
std::vector<int> sq_arr;
std::vector<PifaThree> results;
int temp = 0;
while(std::cin >> temp) //прерывается вводом не-int чего-нибудь
arr.push_back(temp);
if(arr.size() < 3)
std::cout << "3 or more needs";
system("pause");
return 0;
std::sort(arr.begin(), arr.end(), [](int a, int b){ return abs(a) > abs(b); } );
for(auto iter = arr.begin(); iter!= arr.end(); ++iter) sq_arr.push_back(*iter * *iter);
for(size_t i = 0, l = sq_arr.size() - 2; i < l; ++i)
size_t j = i+1;
int half = sq_arr[i] / 2;
while( j < l+1 && sq_arr[j] >= half)
size_t k = j+1;
int a = sq_arr[j] + sq_arr[k];
while( k < l+2 && a >= sq_arr[i] )
if(a == sq_arr[i])
results.push_back( PifaThree(arr[i], arr[j], arr[k]) );
++k;
a = sq_arr[j] + sq_arr[k];
++j;
std::cout << "\n\n";
for(auto iter = arr.begin(); iter!= arr.end(); ++iter) std::cout << " " << *iter;
/*
std::cout << "\n";
for(auto iter = sq_arr.begin(); iter!= sq_arr.end(); ++iter) std::cout << " " << *iter;
*/
for(auto iter = results.begin(); iter!= results.end(); ++iter)
iter->show();
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
struct PifaThree
{
int a;
int b;
int c;
PifaThree()
{
a = 0;
b = 0;
c = 0;
}
PifaThree(int a_, int b_, int c_) : a(a_), b(b_), c(c_)
{
}
~PifaThree() {}
void show()
{
std::cout << a << "^2 = " << b << "^2 + " << c << "^2";
}
};
int main()
{
std::vector<int> arr;
std::vector<int> sq_arr;
std::vector<PifaThree> results;
int temp = 0;
while(std::cin >> temp) //прерывается вводом не-int чего-нибудь
{
arr.push_back(temp);
}
if(arr.size() < 3)
{
std::cout << "3 or more needs";
system("pause");
return 0;
}
std::sort(arr.begin(), arr.end(), [](int a, int b){ return abs(a) > abs(b); } );
for(auto iter = arr.begin(); iter!= arr.end(); ++iter) sq_arr.push_back(*iter * *iter);
for(size_t i = 0, l = sq_arr.size() - 2; i < l; ++i)
{
size_t j = i+1;
int half = sq_arr[i] / 2;
while( j < l+1 && sq_arr[j] >= half)
{
size_t k = j+1;
int a = sq_arr[j] + sq_arr[k];
while( k < l+2 && a >= sq_arr[i] )
{
if(a == sq_arr[i])
{
results.push_back( PifaThree(arr[i], arr[j], arr[k]) );
}
++k;
a = sq_arr[j] + sq_arr[k];
}
++j;
}
}
std::cout << "\n\n";
for(auto iter = arr.begin(); iter!= arr.end(); ++iter) std::cout << " " << *iter;
/*
std::cout << "\n";
for(auto iter = sq_arr.begin(); iter!= sq_arr.end(); ++iter) std::cout << " " << *iter;
*/
std::cout << "\n\n";
for(auto iter = results.begin(); iter!= results.end(); ++iter)
{
iter->show();
std::cout << "\n";
}
system("pause");
return 0;
}