
C/C++
Написать код C++
Вариант 8 пожалуйста

#include
using namespace std;
struct Dot {
double x;
double y;
double length(const Dot& d)const {
return sqrt(pow(d.x - x, 2) + pow(d.y - y, 2));
}
friend ostream& operator
#include <iostream>
#include <vector>
typedef const double& dbl;
double dist(dbl x1, dbl y1, dbl x2, dbl y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
auto find_dist(const std::vector<double>& arr)
{
std::pair<std::vector<double>::const_iterator, std::vector<double>::const_iterator> res;
size_t it1{}, it2{};
double point_distance{}, tmp;
for (it1 = 0; it1 < arr.size() - 2; it1 += 2)
for (it2 = it1 + 2; it2 < arr.size(); it2 += 2)
{
tmp = dist(arr[it1], arr[it1 + 1], arr[it2], arr[it2 + 1]);
if (tmp > point_distance)
{
point_distance = tmp;
res.first = arr.begin() + it1;
res.second = arr.begin() + it2;
}
}
return res;
}
int main()
{
constexpr const size_t size = 10;
std::vector<double> coords(size);
std::cout << "Enter x and y position (x5):";
for (auto& i : coords) std::cin >> i;
auto res = find_dist(coords);
std::cout << "Far distance points at coordinates: { " << *res.first << " , " << *(res.first + 1) << " } and { "
<< *res.second << " , " << *(res.second + 1) << " }";
}
#include <vector>
typedef const double& dbl;
double dist(dbl x1, dbl y1, dbl x2, dbl y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
auto find_dist(const std::vector<double>& arr)
{
std::pair<std::vector<double>::const_iterator, std::vector<double>::const_iterator> res;
size_t it1{}, it2{};
double point_distance{}, tmp;
for (it1 = 0; it1 < arr.size() - 2; it1 += 2)
for (it2 = it1 + 2; it2 < arr.size(); it2 += 2)
{
tmp = dist(arr[it1], arr[it1 + 1], arr[it2], arr[it2 + 1]);
if (tmp > point_distance)
{
point_distance = tmp;
res.first = arr.begin() + it1;
res.second = arr.begin() + it2;
}
}
return res;
}
int main()
{
constexpr const size_t size = 10;
std::vector<double> coords(size);
std::cout << "Enter x and y position (x5):";
for (auto& i : coords) std::cin >> i;
auto res = find_dist(coords);
std::cout << "Far distance points at coordinates: { " << *res.first << " , " << *(res.first + 1) << " } and { "
<< *res.second << " , " << *(res.second + 1) << " }";
}
Похожие вопросы
- Помогите пожалуйста написать код.(C++)
- ПРОШУ, ПОМОГИТЕ НАПИСАТЬ КОД C++
- Помогите написать код c++
- Помогите написать код C++
- Помогите написать код C++ со строками
- Помогите написать код c++ со строками
- Написать код для задачи C++
- Написал код для языка C, но работает не правильно
- Помогите пожалуйста написать код на c++, выводящий имя, фамилию и дату рождения нескольких человек
- Написать код для задачи на C++