티스토리 뷰
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | public class Test { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int test; test = Integer.parseInt(st.nextToken()); int[] score = new int[test]; for(int i=0; i<test; i++) { String answer = br.readLine(); score[i] = cal(answer); } for(int i=0; i<test; i++) System.out.println(score[i]); } public static int cal(String a) { int sum = 0; int score = 0; for(int i=0; i<a.length(); i++) { if(a.charAt(i) == 'O') { score++; sum = sum + score; } else score = 0; } return sum; } } | cs |
'알고리즘 > 백준' 카테고리의 다른 글
| [JAVA] 백준 4796번 (0) | 2020.11.06 |
|---|---|
| [JAVA] 백준 1026번 (0) | 2020.11.05 |
| [JAVA] 백준 1157번 (0) | 2020.11.04 |
| [JAVA] 백준 2851번 (0) | 2020.10.30 |
| [JAVA] 백준 2576번 (0) | 2020.10.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고리즘
- 11729
- 프로그래머스
- 디자인 패턴
- 재귀
- java
- Regex
- recursion
- Stack
- OOP
- 백준
- 순열
- CS
- BFS
- 와일드카드
- 4796
- 게리맨더링
- 제네릭
- 구간 합 구하기
- generic
- 신규아이디추천
- 조합
- 하노이 탑
- 2529
- 백트래킹
- 15686
- 11659
- 래퍼 클래스
- gof
- Wrapper Class
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 26 | 27 | 28 | 29 |
| 30 |
글 보관함