[http://acm.kaist.ac.kr/Problems/2005oa.pdf ë¬¸ì œ 보기] ---- {{{~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ì— í™• 집어 ë„£ê³ í’€ì–´ë„ ê·¸ëƒ¥ 풀린 ë¬¸ì œë¥¼ êµ³ì´ ë©”ì†Œë“œë¡œ ë‚˜ëˆ„ê³ ì—¬ëŸ¬ êµ°ë°ì—ì„œ 사용ë˜ëŠ” 변수를 필드화하는 ê²ƒì´ ì •ë§ ê·€ì°®ì•˜ë‹¤. 하지만 그러한 ë°©ì‹ìœ¼ë¡œ ì „í™˜í•˜ê³ ìŠµê´€í™”í•˜ëŠ” ëŠ¥ë ¥ì„ í‚¤ì›Œì•¼ ê² ë‹¤. ---- [프로그래ë°]