-
Notifications
You must be signed in to change notification settings - Fork 0
/
26.c
36 lines (29 loc) · 788 Bytes
/
26.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
#include <stdio.h>
// memory usage displayed
int main(void) {
char type;
int length;
scanf("%c %d", &type, &length);
int result = 0;
if (type == 'i') {
result = length * sizeof(int);
} else if (type == 'd') {
result = length * sizeof(double);
} else if (type == 'c') {
result = length * sizeof(char);
}
int B, KB, MB;
if (result < 1000) {
printf("%d B\n", result);
} else if (result >= 1000000) {
MB = result / 1000000;
KB = (result % 1000000) / 1000;
B = result % 1000;
printf("%d MB and %d KB and %d B\n", MB, KB, B);
} else if (result >= 1000) {
KB = result / 1000;
B = result % 1000;
printf("%d KB and %d B\n", KB, B);
}
return 0;
}