소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
for(int i=0; i<n; i++) {
String a = scan.nextLine();
int sum=0;
int score=0;
for(int j=0; j<a.length(); j++) {
if(a.charAt(j)=='O') {
score++;
sum +=score;
}else {
score=0;
}
}
System.out.println(sum);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
charAt() 은 문장중에 있는 문자를 추출하는 것.
nextLine()은 문자열을 입력받은 것을 리턴.
nextLine()과 next()메소드의 차이는 nextLine()메소드는 Enter를 치기 전까지 쓴 문자열을 모두 리턴한다는 것이고 next() 메소드는 스페이스 즉 공백 전까지 입력받은 문자열을 리턴한다는 것
'알고리즘 > Java' 카테고리의 다른 글
(JAVA) 백준 알고리즘 7단계 15596번 : 정수 N개의 합 (2) | 2020.05.13 |
---|---|
(JAVA) 백준 알고리즘 6단계 4344번 : 평균은 넘겠지 (0) | 2020.05.11 |
(JAVA) 백준 알고리즘 6단계 1546번 : 평균 (0) | 2020.05.04 |
(JAVA) 백준 알고리즘 6단계 3052번 : 나머지 (0) | 2020.05.03 |
(JAVA) 백준 알고리즘 6단계 2577번 : 숫자의 개수 (3) | 2020.04.25 |