-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3rd_lab.cpp
More file actions
71 lines (70 loc) · 1.47 KB
/
Copy path3rd_lab.cpp
File metadata and controls
71 lines (70 loc) · 1.47 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
#include <bits/stdc++.h>
using namespace std;
class Knapsack{
public:
char c;
int tk;
int kg;
};
void countingSort(int a[], int sz){
int maxVal = a[0];
for(int i = 1; i<sz; i++){
if(a[i] > maxVal){
maxVal = a[i];
}
}
int c[maxVal + 1] = {0};
for(int i = 0; i<sz; i++){
c[a[i]]++;
}
for(int i = 1; i<=maxVal; i++){
c[i] = c[i] + c[i-1];
}
int b[sz];
for(int i = sz-1; i>=0; i--){
b[c[a[i]] - 1] = a[i];
c[a[i]]--;
}
for(int i = 0; i<sz; i++){
a[i] = b[i];
}
// Print array
for(int i = 0; i<sz; i++){
cout << a[i] << " ";
}
cout << endl;
}
void coinChoosing(int taka){
int a[9] = {1000,500,100,50,20,10,5,2,1};
int count = 0;
for(int i = 0; i<9; i++){
if(taka >= a[i]){
int note = taka / a[i];
count += note;
taka = taka % a[i];
}
}
cout << "Note count: " << count << endl;
}
int main(){
int n;
cin >> n;
int a[n];
for(int i = 0; i<n; i++){
cin >> a[i];
}
countingSort(a,n);
int taka;
cin >> taka;
coinChoosing(taka);
int num,maxWeight;
cin >> num >> maxWeight;
Knapsack item[num];
for(int i = 0; i<num; i++){
cin >> item[i].c >> item[i].tk >> item[i].kg;
}
for(int i = 0; i<num; i++){
cout << item[i].c << " " << item[i].tk << " " << item[i].kg << endl;
}
return 0;
}