LINUX.ORG.RU

История изменений

Исправление Uter, (текущая версия) :

Например, так

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

struct point
{ 
    float x;
    float y;
};
    
float distance(const point& first, const point& second)
{
    return sqrt((first.x-second.x)*(first.x-second.x)+(first.y-second.y)*(first.y-second.y));
}
    
int main() 
{
    
    int n;
    cout << "Set dimension of vector\n";
    cin >> n;
    vector<point> points(n);
    point tmp;
    for (int i=0; i<n; i++) 
    {
        cout << "Input x:\n";
        cin >> tmp.x;
        cout << "Input y:\n";
        cin >> tmp.y;
        points.push_back(tmp);
    }
     
          
    auto last=(points.rbegin()+1).base();
    for (auto pos = points.begin(); pos != last; ++pos) 
    {
        cout << distance(*pos, *last) << endl;
    }
    
    return 0;
}

Исходная версия Uter, :

Например, так

[code=cpp]
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

struct point
{
float x;
float y;
};

float distance(const point& first, const point& second)
{
return sqrt((first.x-second.x)*(first.x-second.x)+(first.y-second.y)*(first.y-second.y));
}

int main()
{

int n;
cout << «Set dimension of vector\n»;
cin >> n;
vector<point> points(n);
point tmp;
for (int i=0; i<n; i++)
{
cout << «Input x:\n»;
cin >> tmp.x;
cout << «Input y:\n»;
cin >> tmp.y;
points.push_back(tmp);
}


auto last=(points.rbegin()+1).base();
for (auto pos = points.begin(); pos != last; ++pos)
{
cout << distance(*pos, *last) << endl;
}

return 0;
}
[/code]