본문 바로가기
알고리즘풀이/백준-자바

[백준/JAVA] 8958번 OX퀴즈

by 이얏호이야호 2020. 7. 23.

import java.util.Scanner;

import java.util.Stack;


public class Main {

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int input = in.nextInt();

String insert;

Stack<String> st = new Stack<String>();

int getSum = 0;

int tempt = 1;

for (int i = 0; i < input; i++) {

insert = in.next();

String[] arr = insert.split("");

for (int j = 0; j < arr.length; j++) {

st.add(arr[j]);

}

for (int j = 0; j < arr.length; j++) {

if (st.peek().equals("O")) {

getSum = tempt + getSum;

tempt++;

st.pop();

} else if (st.peek().equals("X")) {

tempt = 1;

st.pop();

}

}

System.out.println(getSum);

st.clear();

getSum = 0;

tempt = 1;


}


}

}

더 많은 백준 코드가 보고 싶다면 ?  https://chuinggun.tistory.com/category/%EB%B0%B1%EC%A4%80


댓글