输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代 表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯 一,则输出按字母序最小的解。
public
class
Main{
public
static
void
main(String[] args){
int
count =
1
;
int
num =
0
;
List<String> strs =
new
ArrayList<String>();
Scanner sc =
new
Scanner(System.in);
while
(sc.hasNextLine()){
if
(count ==
1
){
num = Integer.parseInt(sc.nextLine());
count ++;
}
else
if
(num+
1
>count){
strs.add(sc.nextLine());
count++;
}
else
if
(num+
1
==count){
strs.add(sc.nextLine());
break
;
}
else
{
break
;
}
}
result(strs);
}
public
static
void
result(List<String> strs){
int
v =
0
;
int
p =
0
;
int
f =
0
;
String jia =
""
;
String yi =
""
;
for
(String s:strs){
String[] strss = s.split(
" "
);
if
(change(s) ==
1
){
jia+=strss[
0
];
v++;
}
else
if
(change(s) ==
2
) {
yi+=strss[
1
];
f++;
}
else
{
p++;
}
}
System.out.println(v+
" "
+p+
" "
+f);
System.out.println(f+
" "
+p+
" "
+v);
System.out.print(count(jia)+
" "
+count(yi));
}
public
static
int
change(String s){
String[] strs = s.split(
" "
);
if
(strs[
0
].equals(
"J"
)&&strs[
1
].equals(
"B"
)){
return
1
;
}
else
if
(strs[
0
].equals(
"C"
)&&strs[
1
].equals(
"J"
)){
return
1
;
}
else
if
(strs[
0
].equals(
"B"
)&&strs[
1
].equals(
"C"
)){
return
1
;
}
else
if
(strs[
0
].equals(strs[
1
])){
return
3
;
}
else
{
return
2
;
}
}
public
static
char
count(String s){
char
[] ca = s.toCharArray();
int
B =
0
;
int
C =
0
;
int
J =
0
;
for
(
char
c : ca){
if
(c ==
'B'
){
B++;
}
if
(c==
'C'
){
C++;
}
if
(c==
'J'
){
J++;
}
}
if
(B>=C&&B>=J){
return
'B'
;
}
else
if
(C>B&&C>=J){
return
'C'
;
}
else
{
return
'J'
;
}
}
}