-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab5_Grp1_code.cpp
95 lines (67 loc) · 2.28 KB
/
Lab5_Grp1_code.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
using namespace std;
//Point3D Struct
struct Point3D {
int x;
int y;
int z;
Point3D(){ //default constructor
x = 0;
y = 0;
z = 0;
}
Point3D(int x, int y, int z){ //constructor
this->x = x;
this->y = y;
this->z = z;
}
};
//Calculate Manhattan Distance Function
int findManhattanDistance(Point3D point1, Point3D point2){
int deltaX = abs(point1.x - point2.x);
int deltaY = abs(point1.y - point2.y);
int deltaZ = abs(point1.z - point2.z);
int manhattanDistance = deltaX + deltaY + deltaZ;
return manhattanDistance;
}
//Main
int main (void) {
//cin is temporarily placed in input
string input;
//Stores all points and manhattan distances dynamically
vector<Point3D> pointsVector;
//Finds the number of test cases
getline(cin, input);
int numberOfTestCases = stoi(input);
for(int i = 0; i <= numberOfTestCases-1; i++) {
//Clear the pointsVector at the start of each test case
pointsVector.clear();
//Find the number of points in a test case
getline(cin, input);
int numberOfPoints = stoi(input);
//Creating new points and adding them into the pointArray
for(int i = 0; i <= numberOfPoints-1; i++) {
//Finding the values of coordinates
getline(cin, input, ' ');
int xCoordinate = stoi(input);
getline(cin, input, ' ');
int yCoordinate = stoi(input);
getline(cin, input);
int zCoordinate = stoi(input);
pointsVector.push_back(Point3D(xCoordinate, yCoordinate, zCoordinate));
//cout << pointVector[i].x << pointVector[i].y << pointVector[i].z << endl;
}
// Printing out the contents of pointsVector for each test case. Used for debugging purposes.
// for(int i = 0; i <= numberOfPoints-1; i++){
// cout << pointsVector[i].x << " " << pointsVector[i].y << " " << pointsVector[i].z << endl;
// }
for(int i = 0; i <= numberOfPoints-2; i++){
cout << findManhattanDistance(pointsVector[i], pointsVector[i+1]) << endl;
}
cout << " " << endl;
}
return 0;
}