Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코틀린
- 알고리즘
- Vue
- 에러
- mybatis
- Git
- 스프링
- jquery
- kotlin
- Eclipse
- 자바
- 함수
- JPA
- error
- Java
- 프로그래머스
- IntelliJ
- oracle
- 시큐리티
- 방법
- Spring
- 생성
- GitHub
- JavaScript
- db
- aws
- 오라클
- Security
- 쿼리
- 넥사크로
Archives
- Today
- Total
송민준의 개발노트
프로그래머스-level1-다트 게임(카카오) 본문
https://programmers.co.kr/learn/courses/30/lessons/17682
코딩테스트 연습 - [1차] 다트 게임 | 프로그래머스
programmers.co.kr
카카오 난이도(하) 문제.
1. 점수 부분과 제곱 부분, 옵션부분 구역을 따로따로 정해준다.
2. String 한문장씩 나눠서 각 구역에 맞게 값을 넣어준다.
3. 마지막에 계산 후 더한다.
* 숫자타입인지 확인하는 메소드는 따로 만들어줬음.
public int solution(String dartResult) {
int sum =0;
String[] jumsu = {"","",""};
int[] jumSqrt = {0, 0, 0};
int[] option = {1, 1, 1};
int jumsuIndex = 0;
for(int i =0; i < dartResult.length(); i++) {
String ch = Character.toString(dartResult.charAt(i));
if(isNum(ch)) {
jumsu[jumsuIndex] += ch;
} else {
if(ch.equals("S")) {
jumSqrt[jumsuIndex] = 1;
jumsuIndex++;
} else if(ch.equals("D")) {
jumSqrt[jumsuIndex] = 2;
jumsuIndex++;
} else if(ch.equals("T")){
jumSqrt[jumsuIndex] = 3;
jumsuIndex++;
} else if(ch.equals("*")) {
option[jumsuIndex-1] = 2;
if(jumsuIndex > 1) {
option[jumsuIndex-2] *= 2;
}
} else {
option[jumsuIndex-1] = -1;
}
}
}
for(int i=0; i < 3; i++) {
sum += Math.pow(Integer.parseInt(jumsu[i]),jumSqrt[i])*option[i];
System.out.println("점수 : " + jumsu[i] + " 제곱 : " + jumSqrt[i] + " 옵션 : " +option[i]);
System.out.println("합계 : " + sum);
}
return sum;
}
public static boolean isNum(String s) {
try {
Integer.parseInt(s);
return true;
} catch(NumberFormatException e) {
return false;
}
}
'웹 > JSP' 카테고리의 다른 글
error 처리 페이지 (0) | 2019.11.12 |
---|---|
로그인(방법 2개 : servlet과 jsp활용하여 연결) (0) | 2019.11.11 |
WEB.XML 초기화 파라미터 (0) | 2019.11.11 |
세션(Session) (0) | 2019.11.11 |
표현식(Expression) (0) | 2019.11.11 |