반응형

10799번

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		String totalLine = br.readLine();

		int leftCount = 0;
		int result = 0;

		for (int i = 0; i < totalLine.length(); i++) {
			if (totalLine.charAt(i) == '(') {
				leftCount++;
			} else if (totalLine.charAt(i) == ')') {
				leftCount--;
				if (totalLine.charAt(i - 1) == '(') { // 레이저인 경우
					result = result + leftCount;
				} else {
					result++;
				}
			}
		}

		bw.write(String.valueOf(result));
		bw.flush();
		bw.close();
	}

}
반응형

'알고리즘 > 백준 문제[추후 옮길예정]' 카테고리의 다른 글

[JAVA] 백준 17299번  (0) 2021.05.10
[JAVA] 백준 17298번  (0) 2021.05.10
[JAVA] 백준 17413번  (0) 2021.05.07
[JAVA] 백준 1158번  (0) 2021.05.07
[JAVA] 백준 10845번  (0) 2021.05.07

+ Recent posts