回答編集履歴
1
コードの追加
answer
CHANGED
@@ -2,4 +2,30 @@
|
|
2
2
|
> ・3行分、"cat"又は"dog"のいずれかが入力される。
|
3
3
|
|
4
4
|
この条件があるということはcat又はdogのどちらが**必ず2以上になります**。
|
5
|
-
この事実を使うと短くなると思います。
|
5
|
+
この事実を使うと短くなると思います。
|
6
|
+
|
7
|
+
```java
|
8
|
+
import java.util.*;
|
9
|
+
|
10
|
+
public class Main {
|
11
|
+
public static void main(String[] args) {
|
12
|
+
|
13
|
+
Scanner sc = new Scanner(System.in);
|
14
|
+
int []data = new int[2];
|
15
|
+
String []text = {"cat","dog"};
|
16
|
+
for(int i = 0; i < 3; i++){
|
17
|
+
String line = sc.nextLine();
|
18
|
+
for(int j = 0; j < 2; j++){
|
19
|
+
if(line.equals(text[j])){
|
20
|
+
data[j]++;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
for(int i = 0; i < 2; i++){
|
25
|
+
if(data[i] >= 2){
|
26
|
+
System.out.println(text[i]);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|