AcWing 1725. 组队井字游戏
原题链接
简单
作者:
BLOODHOUND
,
2022-04-01 21:20:09
,
所有人可见
,
阅读 395
java 代码
import java.util.*;
public class Main {
static HashSet<String> res = new HashSet<>();
static int cnt_1 = 0,cnt_2 = 0;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
char[][] g = new char[3][3];
for(int i=0;i<3;i++){
String str = s.next();
for(int j=0;j<3;j++){
g[i][j]=str.charAt(j);
}
}
for(int i=0;i<3;i++){
HashSet<Character> set = new HashSet<>();
for(int j=0;j<3;j++)set.add(g[i][j]);
add(set);
}
for(int j=0;j<3;j++){
HashSet<Character> set = new HashSet<>();
for(int i=0;i<3;i++)set.add(g[i][j]);
add(set);
}
HashSet<Character> set = new HashSet<>();
set.add(g[0][0]); set.add(g[1][1]); set.add(g[2][2]);
add(set);
HashSet<Character> set1 = new HashSet<>();
set1.add(g[0][2]); set1.add(g[1][1]); set1.add(g[2][0]);
add(set1);
System.out.println(cnt_1);
System.out.println(cnt_2);
}
public static void add(HashSet<Character> cur){
if(cur.size()==1){
for(char x:cur){
if(!res.contains(x+" ")){
res.add(x+" ");cnt_1++;
}
}
}
if(cur.size()==2){
List<String> list = new ArrayList<>();
for(char x:cur)list.add(x+"");
Collections.sort(list);
if(!res.contains(list.get(0)+" "+list.get(1))){
res.add(list.get(0)+" "+list.get(1));cnt_2++;
}
}
}
}