回答編集履歴
2
ソースの追加
test
CHANGED
@@ -123,3 +123,117 @@
|
|
123
123
|
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
<追記> 符号が複数の場合のソースコード
|
128
|
+
|
129
|
+
```Java
|
130
|
+
|
131
|
+
import java.util.*;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
public class Main {
|
136
|
+
|
137
|
+
public static void main(String[] args) {
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
Scanner sc = new Scanner(System.in);
|
142
|
+
|
143
|
+
String line = sc.nextLine();
|
144
|
+
|
145
|
+
int count = count_sign(line) + 1;
|
146
|
+
|
147
|
+
int []number = new int[count];
|
148
|
+
|
149
|
+
for(int i = 0; i < count; i++){
|
150
|
+
|
151
|
+
number[i] = 0; /*初期化*/
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
int position = 0;
|
156
|
+
|
157
|
+
int sign = 1;
|
158
|
+
|
159
|
+
for(int i = 0; i < line.length(); i++){
|
160
|
+
|
161
|
+
char c = line.charAt(i);
|
162
|
+
|
163
|
+
if(c == '>'){
|
164
|
+
|
165
|
+
number[position] += sign;
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
else if(c == '<'){
|
170
|
+
|
171
|
+
number[position] += 5 * sign;
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
else if(c == '+'){
|
176
|
+
|
177
|
+
sign = 1;
|
178
|
+
|
179
|
+
position++;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
else if(c == '-'){
|
184
|
+
|
185
|
+
sign = -1;
|
186
|
+
|
187
|
+
position++;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
int sum = 0;
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
for(int i = 0; i < count; i++){
|
200
|
+
|
201
|
+
sum += number[i];
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
System.out.println(sum);
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
public static int count_sign(String line){
|
216
|
+
|
217
|
+
int count = 0;
|
218
|
+
|
219
|
+
for(int i = 0; i < line.length(); i++){
|
220
|
+
|
221
|
+
char c = line.charAt(i);
|
222
|
+
|
223
|
+
if(c == '+' || c == '-'){
|
224
|
+
|
225
|
+
count++;
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
return count;
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
```
|
1
ソースの変更
test
CHANGED
@@ -36,23 +36,21 @@
|
|
36
36
|
|
37
37
|
```Java
|
38
38
|
|
39
|
-
import java.i
|
39
|
+
import java.util.*;
|
40
|
-
|
41
|
-
import java.io.InputStreamReader;
|
42
40
|
|
43
41
|
|
44
42
|
|
45
43
|
public class Main {
|
46
44
|
|
47
|
-
public static void main(String[] args)
|
45
|
+
public static void main(String[] args) {
|
48
46
|
|
49
47
|
// Your code here!
|
50
48
|
|
51
|
-
|
49
|
+
Scanner sc = new Scanner(System.in);
|
52
50
|
|
53
|
-
String line =
|
51
|
+
String line = sc.nextLine();
|
54
52
|
|
55
|
-
int []number = {0,0};
|
53
|
+
int []number = {0,0};//説明の2番目
|
56
54
|
|
57
55
|
int position = 0;
|
58
56
|
|