백준 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 |
'알고리즘과 코테' 카테고리의 다른 글
[Java | 백준 2577번] 숫자의 개수 (0) | 2021.03.23 |
---|---|
[Java | 백준 11724번] 연결 요소의 개수 (0) | 2021.03.22 |
[Java | 백준 2442] 별찍기 - 5 (0) | 2021.03.22 |
[Java | 백준 2440] 별찍기 - 3 (0) | 2021.03.22 |
[Java | 백준 3009] 네 번째 점 (0) | 2021.03.21 |
댓글
최근에 올라온 글
TAG
- 북클럽
- intellij
- filezila
- java
- git연동
- 정보처리기사 필기
- 실용주의프로그래머
- 오늘의코딩
- EC2
- AWS
- 독서후기
- 노개북
- 기술블로그
- JIRA
- SQLD
- spring
- IT 5분 잡학사전
- 노마드코더
- jdbc
- 정보처리기사
- LifecycleException
- 호스팅영역
- 웹페이지만들기
- gradle build
- 정보처리기사 실기
- gradle
- putty
- 개발도서
- ubuntu
- 배포
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함