BackJoon Algorithm - Java

문제

풀이
- BufferedReader 클래스를 사용해 보았다.
- if 문으로 조건을 넣으면 된다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Back_10102 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int v = Integer.parseInt(br.readLine()); // 심사위원 수
char ch[] = new char[v]; // 점수 넣은 char형 배열
for(int i=0;i<v;i++){
ch[i]= (char) br.read(); // 하나씩 넣기
}
int Acount=0;
int Bcount=0;
for(int i=0;i<v;i++){
if(ch[i]=='A'){
Acount++;
}
else if(ch[i]=='B'){
Bcount++;
}
}
if(Acount>Bcount){
System.out.println("A");
}
else if(Acount<Bcount){
System.out.println("B");
}
else{
System.out.println("Tie");
}
br.close();
}
}
댓글남기기