ë¬¸ì œ 보기
----
----
타ì�´ë¨¸ë¥¼ ì¼œë†“ê³ ì‹œê°„ì�„ ìš°ì„ ì‹œí•˜ë‹¤ë³´ë‹ˆ ì—시 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ì—� 확 ì§‘ì–´ ë„£ê³ í’€ì–´ë�„ 그냥 풀린 ë¬¸ì œë¥¼ êµ³ì�´ 메소드로 ë‚˜ëˆ„ê³ ì—¬ëŸ¬ êµ°ë�°ì—�서 사용ë�˜ëŠ” 변수를 필드화하는 것ì�´ ì •ë§� 귀찮았다. 하지만 그러한 ë°©ì‹�으로 ì „í™˜í•˜ê³ ìŠµê´€í™”í•˜ëŠ” ëŠ¥ë ¥ì�„ 키워야 ê² ë‹¤.
----
프로그래�










