본문 바로가기

알고리즘/JAVA

[JAVA] 백준 알고리즘 8958 : OX퀴즈

반응형


OX 퀴즈의 결과를 일차원 배열로 입력받아 점수를 계산합니다



  문제






  소스


import java.util.*; public class Main {     public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String input; int score, scoreSum; sc.nextLine(); for (int i=0; i<n; i++) { // case 수 input = sc.nextLine(); score = 0; scoreSum = 0; for (int j=0; j<input.length(); j++) { if (input.charAt(j) == 'O') { // 정답일 경우 score++; scoreSum += score; } else { score = 0; } } System.out.println(scoreSum); }     } }







  출처


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





반응형