티스토리 뷰

문제를 보자마자 무의식적으로 이중배열을 사용하여 문제를 풀려고 했었다. 이중배열 선언 후, 하나하나 메모리를 할당해주어 방번호를 지정하여 알아내는 방법을 사용하면, 확실하게 구현이 가능했으나, 이건 속도적, 메모리적으로 매우매우매우 비효율적인 방법이다.

이 문제는 나눗셈과 모듈러 연산 한번씩이면 바로 해결되는 아주 간단한 문제이다.

 

Code:

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

public class Main {
	public static void main(String[] args)  throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int i = Integer.parseInt(br.readLine());
		int[] arrayA = new int[i];
		for(int j = 0; j<i; j++) {
			int f, d;
			String hwInput = br.readLine();
			String[] hwn = hwInput.split(" ");
			int h =Integer.parseInt(hwn[0]);
			int w =Integer.parseInt(hwn[1]);
			int n =Integer.parseInt(hwn[2]);
			if(n%h ==0) {
				f = h;
				d = n / h -1;
			} else {
				f = n % h;
				d = n / h;
			}
			arrayA[j] = f*100 + d+1;
		}
		for(int j = 0; j < i; j++) {
			System.out.println(arrayA[j]);
		}
	}
}

 

 

Comments