## Java 풀이 시 유의사항 ##
클래스명은 Main 으로 작성해야함!
💡 문제

💬 입출력 예시

📌 풀이(소스코드)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t > 0) {
String str = br.readLine();
int result = 0;
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'O') {
cnt++;
result += cnt;
}
else {
cnt = 0;
}
}
System.out.println(result);
t--;
}
br.close();
}
}
📄 해설
charAt()
메소드를 사용하여 문자열에서 'O'
를 찾으면 개수를 증가시키고, 이 개수를 result
에 더함
- 도중에
'X'
를 만날 경우, 개수를 0 으로 초기화함
- 문자열 탐색이 끝나면
result
를 출력함