-
Notifications
You must be signed in to change notification settings - Fork 0
/
q9.cpp
67 lines (59 loc) · 1.68 KB
/
q9.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool selColumn(const vector<int>& v1, const vector<int>& v2) {
return v1[1] < v2[1];
}
class Triathlon {
public:
int n;
void Schedule(vector<vector<int>> &data)
{
sort(data.begin() , data.end() , selColumn );
cout << "\n Order of contestants for small completion time\n\n";
for (int i = 0; i < data.size(); i++) {
cout << data[i][0] << "\t";
}
cout << endl;
}
void display(vector<vector<int>> data)
{
cout << "\n-----------------------------------------------------------------";
cout << "\nContestant Number\t|\tSwim Time\t|\tBike Time\t|\tRun Time\n";
cout << "-----------------------------------------------------------------\n";
for ( int i = 0; i < data.size(); i++ ) {
cout << "\t\t" << data[i][0] << "\t\t\t|\t\t" << data[i][1] << "\t\t|\t\t" << data[i][2] << "\t\t|\t" << data[i][3];
cout << endl;
}
}
void Input()
{
cout << "\nEnter Number of contestants\t:\t";
cin >> n;
vector<vector<int>> data(n);
cout << "\nEnter Values";
cout << "\nSwim Time , Bike Time and then Run Time\n";
for ( int i = 0; i < n; i++) {
data[i] = vector<int>(4);
data[i][0] = i + 1;
cin >> data[i][1];
cin >> data[i][2];
cin >> data[i][3];
}
display(data);
Schedule(data);
data.clear();
}
};
int main() {
Triathlon T;
T.Input();
return 0;
/* Time Complexity:
Schedule function takes 0(nlogn) to sort the input
and Input() takes O(n) time
Therefore,
T(n)=O(nlogn) + O(n)
T(n)=O(nlogn)
}