-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistanceBetween.cpp
More file actions
52 lines (47 loc) · 929 Bytes
/
Copy pathDistanceBetween.cpp
File metadata and controls
52 lines (47 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <exception>
using namespace std;
class RemoveStuff{
public:
bool operator()(char c)
{
if (c == ')' || c == '(' || c == ',')
return true;
return false;
}
};
void calculateDistance(vector<int>& v)
{
cout << (sqrt(pow(v[2] - v[0], 2) + pow(v[3] - v[1], 2))) << endl;
}
int main(int argc, const char * argv[])
{
string token;
ifstream ifs(argv[1]);
vector<int> vs;
stringstream ss;
while (getline(ifs, token))
{
token.erase(remove_if(token.begin(), token.end(), [](char c)->bool{if (c == ')' || c == '(' || c == ',')
return true;
return false; }),
token.end());
//cout << token << endl;
ss << token;
while (getline(ss, token,' '))
{
vs.push_back(stoi(token));
}
if (vs.size() == 4){
calculateDistance(vs);
}
ss.clear();
vs.clear();
}
system("pause");
}