回答編集履歴
2
文言修正
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
128で割った時の
|
7
|
+
128で割った時の切り上げの結果を元に、switch文で処理してます。
|
8
8
|
|
9
9
|
速度への影響はわかりませんが、if文よりはいくらかましなんですかね。
|
10
10
|
|
1
提示コードのフォーマット修正
test
CHANGED
@@ -20,119 +20,119 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
int main()
|
23
|
+
int main() {
|
24
24
|
|
25
|
-
|
25
|
+
int alarm_h = 6;
|
26
26
|
|
27
|
-
|
27
|
+
int alarm_m = 30;
|
28
28
|
|
29
|
-
|
29
|
+
vector<int> resistances = {0, 1, 127, 128, 129, 255, 256, 257,
|
30
30
|
|
31
|
-
|
31
|
+
383, 384, 385, 511, 512, 513, 767, 768,
|
32
32
|
|
33
|
-
|
33
|
+
769, 895, 896, 897, 1022, 1023, 1024};
|
34
34
|
|
35
|
-
|
35
|
+
int ans;
|
36
36
|
|
37
|
-
|
37
|
+
for(int i = 0; i < resistances.size(); i++) {
|
38
38
|
|
39
|
-
|
39
|
+
cout << resistances[i] << " ";
|
40
40
|
|
41
|
-
|
41
|
+
ans = (resistances[i] + 128 - 1) / 128;
|
42
42
|
|
43
|
-
|
43
|
+
cout << ans;
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
|
47
|
+
switch(ans) {
|
48
48
|
|
49
|
-
|
49
|
+
case 0: // if (resistance <= 128) {
|
50
50
|
|
51
|
-
|
51
|
+
case 1:
|
52
52
|
|
53
|
-
|
53
|
+
alarm_h = 6;
|
54
54
|
|
55
|
-
|
55
|
+
alarm_m = 0;
|
56
56
|
|
57
|
-
|
57
|
+
cout << " A h:" << alarm_h << " m:" << alarm_m << endl;
|
58
58
|
|
59
|
-
|
59
|
+
break;
|
60
60
|
|
61
|
-
|
61
|
+
case 2: // if (resistance <= 256) {
|
62
62
|
|
63
|
-
|
63
|
+
alarm_h = 6;
|
64
64
|
|
65
|
-
|
65
|
+
alarm_m = 30;
|
66
66
|
|
67
|
-
alarm_m = 30;
|
68
|
-
|
69
|
-
|
67
|
+
cout << " B h:" << alarm_h << " m:" << alarm_m << endl;
|
70
68
|
|
71
69
|
|
72
70
|
|
73
|
-
|
71
|
+
break;
|
74
72
|
|
75
|
-
|
73
|
+
case 3: // else if (resistance <= 384)
|
76
74
|
|
77
|
-
|
75
|
+
alarm_h = 6;
|
78
76
|
|
79
|
-
|
77
|
+
alarm_m = 45;
|
80
78
|
|
81
|
-
|
79
|
+
cout << " C h:" << alarm_h << " m:" << alarm_m << endl;
|
82
80
|
|
83
|
-
|
81
|
+
break;
|
84
82
|
|
85
|
-
|
83
|
+
case 4: // else if (resistance <= 512)
|
86
84
|
|
87
|
-
|
85
|
+
alarm_h = 7;
|
88
86
|
|
89
|
-
|
87
|
+
alarm_m = 0;
|
90
88
|
|
91
|
-
|
89
|
+
cout << " D h:" << alarm_h << " m:" << alarm_m << endl;
|
92
90
|
|
93
|
-
|
91
|
+
break;
|
94
92
|
|
95
|
-
|
93
|
+
case 5: // else if (resistance <= 768)
|
96
94
|
|
97
|
-
|
95
|
+
case 6:
|
98
96
|
|
99
|
-
|
97
|
+
alarm_h = 7;
|
100
98
|
|
101
|
-
|
99
|
+
alarm_m = 30;
|
102
100
|
|
103
|
-
|
101
|
+
cout << " E h:" << alarm_h << " m:" << alarm_m << endl;
|
104
102
|
|
105
|
-
|
103
|
+
break;
|
106
104
|
|
107
|
-
|
105
|
+
case 7: // else if (resistance <= 896)
|
108
106
|
|
109
|
-
|
107
|
+
alarm_h = 8;
|
110
108
|
|
111
|
-
|
109
|
+
alarm_m = 0;
|
112
110
|
|
113
|
-
|
111
|
+
cout << " F h:" << alarm_h << " m:" << alarm_m << endl;
|
114
112
|
|
115
|
-
|
113
|
+
break;
|
116
114
|
|
117
|
-
|
115
|
+
case 8: // else if (resistance <= 1023)
|
118
116
|
|
119
|
-
|
117
|
+
alarm_h = 8;
|
120
118
|
|
121
|
-
|
119
|
+
alarm_m = 30;
|
122
120
|
|
123
|
-
|
121
|
+
cout << " G h:" << alarm_h << " m:" << alarm_m << endl;
|
124
122
|
|
125
|
-
|
123
|
+
break;
|
126
124
|
|
127
|
-
|
125
|
+
default:
|
128
126
|
|
129
|
-
|
127
|
+
break;
|
130
128
|
|
131
|
-
|
129
|
+
}
|
132
130
|
|
133
|
-
|
131
|
+
}
|
134
132
|
|
135
133
|
}
|
134
|
+
|
135
|
+
|
136
136
|
|
137
137
|
|
138
138
|
|