일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- javav 1676
- 백준 2252 줄세우기
- Spring ipfs
- kotiln const
- java 1238
- kotiln const val
- 백준 특정한 최단 경로
- 자바 1676
- 안정해시
- spring mongoTemplate switch
- java 팩토리얼 개수
- mongodb lookup
- Java Call By Refernce
- spring mongodb
- ipfs bean
- spring mongodb switch
- rabbitmq 싱글톤
- ipfs singletone
- spring mongoTemplate
- 백준 연결요소 자바
- nodejs rabbitmq
- 백준 1504 java
- kotiln functional interface
- 전략 패턴이란
- 자바 백준 팩토리얼 개수
- go
- java 1509
- 익명 객체 @transactional
- java 파티
- java 백준 1509
Archives
- Today
- Total
공부 흔적남기기
프로그래머스 [1차] 다트게임 본문
728x90
반응형
import java.util.ArrayList;
class Solution {
public int solution(String dartResult) {
int answer = 0;
char[] chars = dartResult.toCharArray();
ArrayList<String> arrayList = new ArrayList<>();
int i = 0;
//char단위로 쪼개서 문자열로 바꿔서 배열에 넣어주는 과정
while (chars.length != i) {
String str = "";
//"1D2X";
if (Character.isDigit(chars[i])) {
//10처리
if (chars[i] == '1' && chars[i + 1] == '0') {
str += chars[i];
i++;
str += chars[i];
i++;
} else {
str += chars[i];
i++;
}
if (chars.length == i) {
break;
}
while (!Character.isDigit(chars[i])) {
str += chars[i];
i++;
if (chars.length == i) {
break;
}
}
}
arrayList.add(str);
}
int[] scoreSet = new int[arrayList.size()];
ArrayList<Integer> arrayList1 = new ArrayList<>();
int k = 0;
int tmp = 0;
System.out.println(arrayList);
for (String s : arrayList) {
//여기서 부턴 그냥 로직떄로 따라가면 됨
char[] chars1 = s.toCharArray();
for (int j = 0; j < chars1.length; j++) {
System.out.println(chars1[j]);
//10 처리만 잘해주면됨
if (Character.isDigit(chars1[j]) && Character.isDigit(chars1[j + 1])) {
tmp = Integer.parseInt(String.valueOf(chars1[j]) + String.valueOf(chars1[j + 1]));
scoreSet[k] = tmp;
j++;
k++;
//10이 아닌 숫자
} else if (Character.isDigit(chars1[j])) {
tmp = Integer.parseInt(String.valueOf(chars1[j]));
scoreSet[k] = tmp;
k++;
// 문제조건 따라가면 되는 부분들
} else if (chars1[j] == 'D') {
scoreSet[k-1] = scoreSet[k-1] * scoreSet[k-1];
} else if (chars1[j] == 'T') {
scoreSet[k-1] = scoreSet[k-1] * scoreSet[k-1] * scoreSet[k-1];
} else if (chars1[j] == '*') {
// 첫번째 수일 때
if(k == 1) {
scoreSet[k - 1] = scoreSet[k-1] * 2;
}else {
scoreSet[k - 2] = scoreSet[k-2] * 2;
scoreSet[k-1] = scoreSet[k-1] * 2;
}
} else if (chars1[j] == '#') {
scoreSet[k - 1] = -scoreSet[k - 1];
}
}
}
for (int i1 : scoreSet) {
answer += i1;
}
return answer;
}
}
문제 : https://programmers.co.kr/learn/courses/30/lessons/17682
코딩테스트 연습 - [1차] 다트 게임
programmers.co.kr
728x90
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
SQL 명령어 복기 (0) | 2025.02.04 |
---|---|
프로그래머스 크레인 인형뽑기 게임 (0) | 2022.01.17 |
프로그래머스 키패드 누르기 (0) | 2022.01.17 |
프로그래머스 [1차] 비밀지도 (0) | 2022.01.17 |
프로그래머스 폰켓몬 (0) | 2022.01.17 |