https://www.acmicpc.net/problem/8958
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net
charAt() 메서드 이용하기
package s05_array;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MJ_06_8958 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int R = Integer.parseInt(br.readLine());
//int array[] = new int[R];
String array[] = new String[R]; //*
for(int i=0;i<R;i++) {
array[i]=br.readLine();
}
for(int i=0;i<R;i++) {
int count=0;
int sum=0;
for(int j=0;j<array[i].length();j++) {//*
if(array[i].charAt(j)=='O') { //*
count++;
}else {
count=0;
}
sum+=count;
}
System.out.println(sum);
}
}
}
getbyte()메서드 다시
'ONLINE JUDGE > 배열' 카테고리의 다른 글
[백준4344] 평균은 넘겠지 (0) | 2022.03.01 |
---|---|
[백준1546] 평균 (0) | 2022.02.24 |
[백준3052] 나머지 (0) | 2022.02.23 |
[백준2562] 최댓값 다시보기 (0) | 2022.02.10 |
[백준10818] 최소, 최대 (0) | 2022.02.09 |
댓글