study/알고리즘 문제 풀이

[JAVA] 27918 탁구 경기

dddzr 2023. 3. 30. 22:17

https://www.acmicpc.net/problem/27918

 

27918번: 탁구 경기

달구와 포닉스는 탁구 치는 것을 좋아한다. 윤이는 오늘도 탁구를 치는 달구와 포닉스를 보고, 누가 경기에서 승리할지 예측해 보기로 했다. 달구와 포닉스가 탁구 경기를 진행하는 규칙은 다음

www.acmicpc.net

 

import java.util.Scanner;
import java.util.ArrayList;
import java.lang.Math;

class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int numOfGame = sc.nextInt();
    ArrayList<String> winnerList = new ArrayList<String>();
    for (int i = 0; i < numOfGame; i++) {
      winnerList.add(sc.next());
    }

    int Dscore = 0;
    int Pscore = 0;
    for (int i = 0; i < winnerList.size(); i++) {
      String winner = winnerList.get(i);
      if (winner.equals("D")) {
        Dscore++;
      } else if (winner.equals("P")) {
        Pscore++;
      }
      int gap = Math.abs(Dscore - Pscore);
      if (gap >= 2) {
        break;
      }
    }
    System.out.println(Dscore + ":" + Pscore);
  }
}

'study > 알고리즘 문제 풀이' 카테고리의 다른 글

유기농 배추 (백준 1012)  (0) 2023.05.13
BFS와 DFS (백준 1260)  (0) 2023.05.03
[python] 2293 동전1  (0) 2022.06.09
[python] 1026 보물  (0) 2022.06.09
[python] 1002 터렛  (0) 2022.06.09