回答編集履歴

2

文言修正

2022/01/04 16:36

投稿

Crimson_Tide
Crimson_Tide

スコア509

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- 128で割った時のり上げの結果を元に、switch文で処理してます。
7
+ 128で割った時のり上げの結果を元に、switch文で処理してます。
8
8
 
9
9
  速度への影響はわかりませんが、if文よりはいくらかましなんですかね。
10
10
 

1

提示コードのフォーマット修正

2022/01/04 16:36

投稿

Crimson_Tide
Crimson_Tide

スコア509

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
- int alarm_h = 6;
27
+ int alarm_m = 30;
28
28
 
29
- int alarm_m = 30;
29
+ vector<int> resistances = {0, 1, 127, 128, 129, 255, 256, 257,
30
30
 
31
- vector<int> resistances = {0, 1, 127, 128, 129, 255, 256, 257, 383, 384, 385, 511, 512, 513, 767, 768, 769, 895, 896, 897, 1022, 1023, 1024};
31
+ 383, 384, 385, 511, 512, 513, 767, 768,
32
32
 
33
- int ans;
33
+ 769, 895, 896, 897, 1022, 1023, 1024};
34
34
 
35
- for (int i = 0; i < resistances.size(); i++)
35
+ int ans;
36
36
 
37
- {
37
+ for(int i = 0; i < resistances.size(); i++) {
38
38
 
39
- cout << resistances[i] << " ";
39
+ cout << resistances[i] << " ";
40
40
 
41
- ans = (resistances[i] + 128 - 1) / 128;
41
+ ans = (resistances[i] + 128 - 1) / 128;
42
42
 
43
- cout << ans;
43
+ cout << ans;
44
44
 
45
45
 
46
46
 
47
- switch (ans)
47
+ switch(ans) {
48
48
 
49
- {
49
+ case 0: // if (resistance <= 128) {
50
50
 
51
- case 0: // if (resistance <= 128) {
51
+ case 1:
52
52
 
53
- case 1:
53
+ alarm_h = 6;
54
54
 
55
- alarm_h = 6;
55
+ alarm_m = 0;
56
56
 
57
- alarm_m = 0;
57
+ cout << " A h:" << alarm_h << " m:" << alarm_m << endl;
58
58
 
59
- cout << " A h:" << alarm_h << " m:" << alarm_m << endl;
59
+ break;
60
60
 
61
- break;
61
+ case 2: // if (resistance <= 256) {
62
62
 
63
- case 2: //if (resistance <= 256) {
63
+ alarm_h = 6;
64
64
 
65
- alarm_h = 6;
65
+ alarm_m = 30;
66
66
 
67
- alarm_m = 30;
68
-
69
- cout << " B h:" << alarm_h << " m:" << alarm_m << endl;
67
+ cout << " B h:" << alarm_h << " m:" << alarm_m << endl;
70
68
 
71
69
 
72
70
 
73
- break;
71
+ break;
74
72
 
75
- case 3: // else if (resistance <= 384)
73
+ case 3: // else if (resistance <= 384)
76
74
 
77
- alarm_h = 6;
75
+ alarm_h = 6;
78
76
 
79
- alarm_m = 45;
77
+ alarm_m = 45;
80
78
 
81
- cout << " C h:" << alarm_h << " m:" << alarm_m << endl;
79
+ cout << " C h:" << alarm_h << " m:" << alarm_m << endl;
82
80
 
83
- break;
81
+ break;
84
82
 
85
- case 4: // else if (resistance <= 512)
83
+ case 4: // else if (resistance <= 512)
86
84
 
87
- alarm_h = 7;
85
+ alarm_h = 7;
88
86
 
89
- alarm_m = 0;
87
+ alarm_m = 0;
90
88
 
91
- cout << " D h:" << alarm_h << " m:" << alarm_m << endl;
89
+ cout << " D h:" << alarm_h << " m:" << alarm_m << endl;
92
90
 
93
- break;
91
+ break;
94
92
 
95
- case 5: // else if (resistance <= 768)
93
+ case 5: // else if (resistance <= 768)
96
94
 
97
- case 6:
95
+ case 6:
98
96
 
99
- alarm_h = 7;
97
+ alarm_h = 7;
100
98
 
101
- alarm_m = 30;
99
+ alarm_m = 30;
102
100
 
103
- cout << " E h:" << alarm_h << " m:" << alarm_m << endl;
101
+ cout << " E h:" << alarm_h << " m:" << alarm_m << endl;
104
102
 
105
- break;
103
+ break;
106
104
 
107
- case 7: // else if (resistance <= 896)
105
+ case 7: // else if (resistance <= 896)
108
106
 
109
- alarm_h = 8;
107
+ alarm_h = 8;
110
108
 
111
- alarm_m = 0;
109
+ alarm_m = 0;
112
110
 
113
- cout << " F h:" << alarm_h << " m:" << alarm_m << endl;
111
+ cout << " F h:" << alarm_h << " m:" << alarm_m << endl;
114
112
 
115
- break;
113
+ break;
116
114
 
117
- case 8: // else if (resistance <= 1023)
115
+ case 8: // else if (resistance <= 1023)
118
116
 
119
- alarm_h = 8;
117
+ alarm_h = 8;
120
118
 
121
- alarm_m = 30;
119
+ alarm_m = 30;
122
120
 
123
- cout << " G h:" << alarm_h << " m:" << alarm_m << endl;
121
+ cout << " G h:" << alarm_h << " m:" << alarm_m << endl;
124
122
 
125
- break;
123
+ break;
126
124
 
127
- default:
125
+ default:
128
126
 
129
- break;
127
+ break;
130
128
 
131
- }
129
+ }
132
130
 
133
- }
131
+ }
134
132
 
135
133
  }
134
+
135
+
136
136
 
137
137
 
138
138