Skip to content

Commit ecc5382

Browse files
committed
[level 0] Title: 조건 문자열, Time: 0.03 ms, Memory: 83.6 MB -BaekjoonHub
1 parent c46d024 commit ecc5382

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [level 0] 조건 문자열 - 181934
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/181934)
4+
5+
### 성능 요약
6+
7+
메모리: 83.6 MB, 시간: 0.03 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩 기초 트레이닝
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 03월 19일 16:57:01
20+
21+
### 문제 설명
22+
23+
<p>문자열에 따라 다음과 같이 두 수의 크기를 비교하려고 합니다. </p>
24+
25+
<ul>
26+
<li>두 수가 <code>n</code>과 <code>m</code>이라면
27+
28+
<ul>
29+
<li>"&gt;", "=" : <code>n</code> &gt;= <code>m</code></li>
30+
<li>"&lt;", "=" : <code>n</code> &lt;= <code>m</code></li>
31+
<li>"&gt;", "!" : <code>n</code> &gt; <code>m</code></li>
32+
<li>"&lt;", "!" : <code>n</code> &lt; <code>m</code> </li>
33+
</ul></li>
34+
</ul>
35+
36+
<p>두 문자열 <code>ineq</code>와 <code>eq</code>가 주어집니다. <code>ineq</code>는 "&lt;"와 "&gt;"중 하나고, <code>eq</code>는 "="와 "!"중 하나입니다. 그리고 두 정수 <code>n</code>과 <code>m</code>이 주어질 때, <code>n</code>과 <code>m</code>이 <code>ineq</code>와 <code>eq</code>의 조건에 맞으면 1을 아니면 0을 return하도록 solution 함수를 완성해주세요.</p>
37+
38+
<hr>
39+
40+
<h5>제한 사항</h5>
41+
42+
<ul>
43+
<li>1 ≤ <code>n</code>, <code>m</code> ≤ 100</li>
44+
</ul>
45+
46+
<hr>
47+
48+
<h5>입출력 예</h5>
49+
<table class="table">
50+
<thead><tr>
51+
<th>ineq</th>
52+
<th>eq</th>
53+
<th>n</th>
54+
<th>m</th>
55+
<th>result</th>
56+
</tr>
57+
</thead>
58+
<tbody><tr>
59+
<td>"&lt;"</td>
60+
<td>"="</td>
61+
<td>20</td>
62+
<td>50</td>
63+
<td>1</td>
64+
</tr>
65+
<tr>
66+
<td>"&gt;"</td>
67+
<td>"!"</td>
68+
<td>41</td>
69+
<td>78</td>
70+
<td>0</td>
71+
</tr>
72+
</tbody>
73+
</table>
74+
<hr>
75+
76+
<h5>입출력 예 설명</h5>
77+
78+
<p>입출력 예 #1</p>
79+
80+
<ul>
81+
<li>20 &lt;= 50은 참이기 때문에 1을 return합니다.</li>
82+
</ul>
83+
84+
<p>입출력 예 #2</p>
85+
86+
<ul>
87+
<li>41 &gt; 78은 거짓이기 때문에 0을 return합니다.</li>
88+
</ul>
89+
90+
<hr>
91+
92+
<p>※ 2023.05.31 테스트 케이스가 수정되었습니다. 기존에 제출한 코드가 통과하지 못할 수도 있습니다.</p>
93+
94+
95+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int solution(String ineq, String eq, int n, int m) {
3+
int answer = 0;
4+
5+
if(ineq.equals(">") && eq.equals("=")){
6+
answer = n>=m ? 1 : 0;
7+
}
8+
else if(ineq.equals("<") && eq.equals("=")){
9+
answer = n<=m ? 1 : 0;
10+
}
11+
else if(ineq.equals(">") && eq.equals("!")){
12+
answer = n>m ? 1 : 0;
13+
}
14+
else if(ineq.equals("<") && eq.equals("!")){
15+
answer = n<m ? 1 : 0;
16+
}
17+
18+
return answer;
19+
}
20+
}

0 commit comments

Comments
 (0)