백준 #27918번 탁구 경기

jhj·2024년 2월 17일

백준 JAVA

목록 보기
354/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int countD = 0;
		int countP = 0;
		String[] w = new String[n];
		int d = 0;
		
		for(int i = 0; i < w.length; i++) {
			w[i] = sc.next();
		}
		
		for(int i = 0; i < w.length; i++) {
			if(w[i].equals("D")) {
				countD++;
			}else if(w[i].equals("P")) {
				countP++;
			}
			
			if(countD > countP) {
				d = countD - countP;
			}else {
				d = countP - countD;
			}
			
			if(d >= 2) {
				break;
			}
		}
		System.out.println(countD + ":" + countP);
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글