-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShoemaker.cpp
More file actions
92 lines (73 loc) · 2.38 KB
/
Copy pathShoemaker.cpp
File metadata and controls
92 lines (73 loc) · 2.38 KB
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
#include <algorithm>
#include <iostream>
#include <vector>
/**
* Problem statement can be viewed at:
* http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110405&format=html
*
* @author Quinn Liu (quinnliu@vt.edu)
* @author Jason Riddle (jr1285@vt.edu)
*
* The following is a solution for the above problem.
*/
using namespace std;
class ShoeOrderInfo {
private:
int _index;
int _timeInDays;
int _paymentPerStartLateDay;
public:
ShoeOrderInfo(int index, int timeInDays, int paymentPerStartLateDay) :
_index(index), _timeInDays(timeInDays), _paymentPerStartLateDay(
paymentPerStartLateDay) {
}
bool operator <(const ShoeOrderInfo & shoeOrderInfo) const {
int cost1 = _timeInDays * shoeOrderInfo._paymentPerStartLateDay;
int cost2 = shoeOrderInfo._timeInDays * _paymentPerStartLateDay;
return cost1 < cost2 ?
true : (cost1 == cost2 ? _index < shoeOrderInfo._index : false);
}
int getIndex() const {
return _index;
}
static bool compareShoeOrderInfos(const ShoeOrderInfo * shoeOrderInfo1,
const ShoeOrderInfo * shoeOrderInfo2) {
return *shoeOrderInfo1 < *shoeOrderInfo2;
}
};
int main() {
int numberOfTestCases = 0;
cin >> numberOfTestCases;
for (int i = 0; i < numberOfTestCases; i++) {
int numberOfJobs;
cin >> numberOfJobs;
vector<ShoeOrderInfo> shoeOrderInfos;
vector<ShoeOrderInfo*> listOfShoeOrdersToBeSorted;
shoeOrderInfos.reserve(numberOfJobs);
listOfShoeOrdersToBeSorted.reserve(numberOfJobs);
for (int currentJob = 1; currentJob <= numberOfJobs; currentJob++) {
int currentJobTimeInDaysToComplete;
int currentJobPaymentPerStartLateDay;
cin >> currentJobTimeInDaysToComplete
>> currentJobPaymentPerStartLateDay;
shoeOrderInfos.push_back(
ShoeOrderInfo(currentJob, currentJobTimeInDaysToComplete,
currentJobPaymentPerStartLateDay));
listOfShoeOrdersToBeSorted.push_back(&shoeOrderInfos.back());
}
sort(listOfShoeOrdersToBeSorted.begin(),
listOfShoeOrdersToBeSorted.end(),
ShoeOrderInfo::compareShoeOrderInfos);
if (i) {
cout << endl;
}
for (int currentJob = 0; currentJob < numberOfJobs; currentJob++) {
if (currentJob) {
cout << ' ';
}
cout << listOfShoeOrdersToBeSorted[currentJob]->getIndex();
}
cout << endl;
}
return 0;
}