문 보기
----
----
머를 놓고 다보 Refactoring 고 다. 구 고 감 는 문는 그냥 막 딩는 다. main 고 그냥 린 문를 굳 메드로 나고 러 군데 되는 변를 드는 것 말 귀다. 만 그러 방로 고 관는 능력 겠다.
----
로그래밍
----
~java import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Shopping { private static BufferedReader br; public static int processOneCase(int num) { String line = null; String [] contents; double [][] rates = new double[num][2]; for(int i = 0; i < num; i++) { try { line = br.readLine(); } catch (IOException e) { e.printStackTrace(); } contents = line.split(" "); int price = Integer.parseInt(contents[1]); int weight = Integer.parseInt(contents[0]); rates[i][0] = (double) price / weight; rates[i][1] = price; } double minRate = rates[0][0]; int minRateIndex = 0; for(int i = 1; i < num; i++) { if (rates[i][0] < minRate) { minRate = rates[i][0]; minRateIndex = i; } else if (rates[i][0] == minRate) { if (rates[i][1] < rates[minRateIndex][1]) { minRate = rates[i][0]; minRateIndex = i; } } } return (int) rates[minRateIndex][1]; } public static void main(String[] args) { br = null; try { br = new BufferedReader(new FileReader("test.txt")); String line = br.readLine(); int testCase = Integer.parseInt(line); for(int i = 0; i < testCase; i++) { line = br.readLine(); int result = processOneCase(Integer.parseInt(line)); System.out.println(result); } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }: 30m
----
머를 놓고 다보 Refactoring 고 다. 구 고 감 는 문는 그냥 막 딩는 다. main 고 그냥 린 문를 굳 메드로 나고 러 군데 되는 변를 드는 것 말 귀다. 만 그러 방로 고 관는 능력 겠다.
----
로그래밍