[Java | 백준 10250] ACM 호텔
· 테크· Java
Java
백준 10250번 www.acmicpc.net/problem/10250
풀이
문제 길이가 난이도에 영향을 미친게 아닐까하는 생각이 드는 문제입니다.
문제를 보면, 엘리베이터에서 가깝다면 1층보다 엘리베이터에 가까운 호실로 배정한다는 것을 알 수 있다. 즉, 102호실 전에 각 층의 01호실부터 채워진다는 것이다.
따라서 n 번째 손님은 h 로 나눈 값에 따라 배정받는 호실번호를 파악할 수 있다. 그리고 여기서 나눈 나머지가 없다면 h 층에 있는 호실에 배정되었음을 알 수 있다. 이 부분을 해결하기 위해 삼항연산자로 출력 또는 대입 값을 별도로 설정했다.
|
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
|
import java.util.*;
public class Math_10250 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cnt = sc.nextInt();
int floor = 0, roomno = 0;
String sfloor = "", sroomno = "";
for(int i=0; i<cnt; i++) {
int h = sc.nextInt();
int w = sc.nextInt();
int n = sc.nextInt();
floor = (n%h==0)? h : n%h;
roomno = (n%h==0)? n/h : n/h+1;
sfloor = String.valueOf(floor);
sroomno = (roomno<10)? "0"+String.valueOf(roomno):String.valueOf(roomno);
System.out.println(sfloor+sroomno);
}
sc.nextLine();
sc.close();
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319