質問編集履歴
1
code
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,173 +1,3 @@
|
|
1
|
-
```package hitandblow;
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
import java.io.BufferedReader;
|
6
|
-
|
7
|
-
import java.io.IOException;
|
8
|
-
|
9
|
-
import java.io.InputStreamReader;
|
10
|
-
|
11
|
-
import java.util.ArrayList;
|
12
|
-
|
13
|
-
import java.util.Collections;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
public class hitandblow02 {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
public static void main(String[] args)throws IOException {
|
22
|
-
|
23
|
-
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
24
|
-
|
25
|
-
ArrayList<Integer> list = new ArrayList<Integer>();
|
26
|
-
|
27
|
-
String str = "5桁の数字を入力してください。";
|
28
|
-
|
29
|
-
String ans ="";
|
30
|
-
|
31
|
-
int num[] = new int[5];
|
32
|
-
|
33
|
-
int count = 0;
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
for(int i = 0; i <= 10; i++) {
|
38
|
-
|
39
|
-
list.add(i);
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
Collections.shuffle(list);
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
for(int i =0; i < num.length; i++) {
|
48
|
-
|
49
|
-
num[i] = list.get(i);
|
50
|
-
|
51
|
-
System.out.print(num[i]);
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
while(true) {
|
60
|
-
|
61
|
-
System.out.println("");
|
62
|
-
|
63
|
-
System.out.print(str);
|
64
|
-
|
65
|
-
ans = br.readLine();
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if(ans.length() == 5) {
|
70
|
-
|
71
|
-
str = "5桁の数字を入力してください。";
|
72
|
-
|
73
|
-
count++;
|
74
|
-
|
75
|
-
ArrayList<Integer> player = new ArrayList<Integer>();
|
76
|
-
|
77
|
-
player.add((Integer.parseInt(ans) / 10000)% 10);
|
78
|
-
|
79
|
-
player.add((Integer.parseInt(ans) / 1000)% 10);
|
80
|
-
|
81
|
-
player.add((Integer.parseInt(ans) / 100)% 10);
|
82
|
-
|
83
|
-
player.add((Integer.parseInt(ans) / 10)% 10);
|
84
|
-
|
85
|
-
player.add(Integer.parseInt(ans) % 10);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
int hit = 0;
|
90
|
-
|
91
|
-
for(int i = 0; i < num.length; i++) {
|
92
|
-
|
93
|
-
if(player.get(i) == num[i]) {
|
94
|
-
|
95
|
-
hit++;
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
int blow = 0;
|
104
|
-
|
105
|
-
for(int i = 0; i < num.length; i++) {
|
106
|
-
|
107
|
-
for(int j = 0; j < num.length; j++) {
|
108
|
-
|
109
|
-
if(player.get(i) == num[j]) {
|
110
|
-
|
111
|
-
blow++;
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
if(hit == 5) {
|
120
|
-
|
121
|
-
System.out.println("おめでとう!" + count + "回目で成功♪");
|
122
|
-
|
123
|
-
break;
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
System.out.println("ヒット :" + hit + "個、 ブロー:" + (blow - hit) + "個");
|
130
|
-
|
131
|
-
System.out.println("");
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
if(count % 3 == 0) {
|
136
|
-
|
137
|
-
System.out.print("ヒント : ");
|
138
|
-
|
139
|
-
for(int i = 1; i <= (count / 3); i++) {
|
140
|
-
|
141
|
-
System.out.print(num[i - 1]);
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
}else {
|
146
|
-
|
147
|
-
str = "5桁の数字を入力してください。";
|
148
|
-
|
149
|
-
System.out.println("");
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
str = "5桁の数字を入力してください。";
|
154
|
-
|
155
|
-
System.out.println("");
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
コード
|
168
|
-
|
169
|
-
```
|
170
|
-
|
171
1
|
```package hitandblow;
|
172
2
|
|
173
3
|
|