Skip to content

Commit f2122d1

Browse files
committed
[level 0] Title: 수 조작하기 1, Time: 11.60 ms, Memory: 95.7 MB -BaekjoonHub
1 parent eaa548c commit f2122d1

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [level 0] 수 조작하기 1 - 181926
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/181926)
4+
5+
### 성능 요약
6+
7+
메모리: 95.7 MB, 시간: 11.60 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩 기초 트레이닝
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 03월 07일 20:07:39
20+
21+
### 문제 설명
22+
23+
<p>정수 <code>n</code>과 문자열 <code>control</code>이 주어집니다. <code>control</code>은 "w", "a", "s", "d"의 4개의 문자로 이루어져 있으며, <code>control</code>의 앞에서부터 순서대로 문자에 따라 <code>n</code>의 값을 바꿉니다.</p>
24+
25+
<ul>
26+
<li>"w" : <code>n</code>이 1 커집니다.</li>
27+
<li>"s" : <code>n</code>이 1 작아집니다.</li>
28+
<li>"d" : <code>n</code>이 10 커집니다.</li>
29+
<li>"a" : <code>n</code>이 10 작아집니다.</li>
30+
</ul>
31+
32+
<p>위 규칙에 따라 <code>n</code>을 바꿨을 때 가장 마지막에 나오는 <code>n</code>의 값을 return 하는 solution 함수를 완성해 주세요.</p>
33+
34+
<hr>
35+
36+
<h5>제한사항</h5>
37+
38+
<ul>
39+
<li>-100,000 ≤ <code>n</code> ≤ 100,000</li>
40+
<li>1 ≤ <code>control</code>의 길이 ≤ 100,000
41+
42+
<ul>
43+
<li><code>control</code>은 알파벳 소문자 "w", "a", "s", "d"로 이루어진 문자열입니다.</li>
44+
</ul></li>
45+
</ul>
46+
47+
<hr>
48+
49+
<h5>입출력 예</h5>
50+
<table class="table">
51+
<thead><tr>
52+
<th>n</th>
53+
<th>control</th>
54+
<th>result</th>
55+
</tr>
56+
</thead>
57+
<tbody><tr>
58+
<td>0</td>
59+
<td>"wsdawsdassw"</td>
60+
<td>-1</td>
61+
</tr>
62+
</tbody>
63+
</table>
64+
<hr>
65+
66+
<h5>입출력 예 설명</h5>
67+
68+
<p>입출력 예 #1</p>
69+
70+
<ul>
71+
<li>수 <code>n</code>은 <code>control</code>에 따라 다음과 같은 순서로 변하게 됩니다.</li>
72+
<li>0 → 1 → 0 → 10 → 0 → 1 → 0 → 10 → 0 → -1 → -2 → -1</li>
73+
<li>따라서 -1을 return 합니다.</li>
74+
</ul>
75+
76+
77+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int solution(int n, String control) {
3+
int answer = n;
4+
for(int i = 0; i < control.length(); i++) {
5+
if (control.charAt(i) == 'w') {
6+
answer += 1;
7+
} else if (control.charAt(i) == 's') {
8+
answer -= 1;
9+
} else if (control.charAt(i) == 'd') {
10+
answer += 10;
11+
} else if (control.charAt(i) == 'a') {
12+
answer -= 10;
13+
}
14+
}
15+
return answer;
16+
}
17+
}

0 commit comments

Comments
 (0)