본문 바로가기
알고리즘

백준 알고리즘 10250 - ACM 호텔

by C0deWave 2020. 3. 20.


이번 문제는 문제를 푸는데 시간이 좀 걸렸다.


나누기를 할때 정확히 나누어 떨어지면 만약 6층인데 6번째 손님이 오면 나머지가 0이 되기 때문에 이를 어떻게 6으로 출력할지 고민을 했던것 같다.

package baek10250;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int testcase = Integer.parseInt(bf.readLine());
		
		StringTokenizer st;
		String string = "";
		
		int h, w, n;
		
		for (int i = 0; i < testcase ; i++) {
			string = bf.readLine();
			st = new StringTokenizer(string);

			h = Integer.parseInt(st.nextToken());
			w = Integer.parseInt(st.nextToken());
			n = Integer.parseInt(st.nextToken());
			
			calculate(h, w, n);
		}
	}
	
	public static void calculate(int h, int w, int n) {
		int dong;
		int ho;
		dong = (n%h) == 0 ? h : (n%h);
		ho = (n%h) == 0? (n/h) : (n/h)+1;
		
		System.out.printf("%d%02d\n",dong,ho);
	}
}

그래도 잘 풀어서 다행이다.

https://www.acmicpc.net/problem/10250

댓글