-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcfs.c
72 lines (65 loc) · 1.09 KB
/
fcfs.c
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
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#define CPUIO_MAX 20
#define P_MAX 10
struct Process {
int atime;
int priority;
int cpuio[CPUIO_MAX];
};
int readProcess(struct Process *pc){
int minus = false;
int n = 0;
int i = 0;
char c;
while(scanf("%c", &c) != EOF){
if(minus){
if(c == '1'){
pc->cpuio[i-2] = -1;
return 0;
} else {
printf("invalid input");
return -1;
}
} else if(isdigit(c)){
n *= 10;
n += (int)(c-'0');
} else if(c == ' '){
if(i == 0){
pc->atime = n;
} else if(i == 1){
pc->priority = n;
} else {
pc->cpuio[i-2] = n;
}
n = 0;
i++;
} else if(c == '-'){
minus = true;
}
}
return EOF;
}
int main(int argc, char *argv[]){
struct Process pcss[P_MAX];
int n_pcss;
// read input
for(n_pcss=0; readProcess(&pcss[n_pcss]) != EOF; n_pcss++){
;
}
// print input
printf("number of processes: %d\n", n_pcss);
int k;
for(int i=0; i<n_pcss; i++){
for(int j=0; j<CPUIO_MAX; j++){
k = (&pcss[i])->cpuio[j];
if(k == -1){
break;
}
printf("%d\n", k);
}
printf("\n");
}
return 0;
}