-
Notifications
You must be signed in to change notification settings - Fork 0
/
worst-fit.cpp
44 lines (39 loc) · 1.57 KB
/
worst-fit.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int hole; // Number of free memory holes
cin >> hole;
vector<int> holes(hole);
for (int i = 0; i < hole; i++)
{
cin >> holes[i]; // Free memory hole's size
}
int size; // Process size
cin >> size;
sort(holes.begin(), holes.end());
if (holes.back() >= size)
{
cout << "The process is allocated into " << holes.back()
<< " mb memory hole.";
}
else cout << "No suitable hole available!";
}
/*//... Sample Input-Output:
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Input:
7
12 3 5 32 43 9 7
27
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Output:
The process is allocated into 32 mb memory hole.
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Input:
7
12 3 5 32 43 9 7
45
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Output:
No suitable hole available!
*///...