Skip to content

Conversation

Chaeonida
Copy link
Collaborator

No description provided.

@Chaeonida Chaeonida changed the title 1주차 알고리즘 스터디 문제풀이 코드 - 김채원 #3 1주차 알고리즘 스터디 문제풀이 코드 - 김채원 Aug 17, 2021
Comment on lines +24 to +25
curX += dx[dir] * dis;
curY += dy[dir] * dis;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 dis 만큼 1을 더하거나 빼는 반복문을 돌렸는데 이걸 보니 굳이 그럴 필요가 없었네요 ㅋㅋㅋ

Comment on lines +36 to +38
} catch (IOException e) {
e.printStackTrace();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS 환경에서 IOException이 발생할 일은 거의 없을테니 메서드에 throws만 해주셔도 괜찮을 것 같아요

Comment on lines +24 to +34
for(int i=0; i<101; i++){
if(!(list.get(i).size() <= 1)){
int k = list.get(i).get(0);
for(int j=1; j<list.get(i).size(); j++){
if(k != list.get(i).get(j)){
k = list.get(i).get(j);
sum++;
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 알고리즘이 조금 이해가 안가는데 설명해주실 수 있나요?😮

cTmp = tmp.charAt(j);
save = "";
boolean check = false;
while(cTmp >= '0' && cTmp <= '9') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어제 리뷰에서 나왔던 것처럼 Character.isDigit 메서드를 활용하면 좋을 것 같네요

// 첫 번째와 두 번째가 모두 0이다. 이는 0 그대로. > 아무것도 하지 않아도 됨
}
else // 첫 번째 값이지만 0이 아닌 경우 어떤 값이 들어와도 상관 없음.
save += cTmp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문자열 concatenation 연산을 수행할 때는 '+' 연산자 대신 StringBuilder나 StringBuffer를 쓰는 게 좋을 것 같습니다!

Comment on lines +15 to +17
private int minDayOfAge,maxDayOfAge=0;
private int minMonthOfAge,maxMonthOfAge=0;
private int minYearOfAge,maxYearOfAge =0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 int 기본값은 0으로 초기화되기 때문에 일일히 안 해주셔도 될 것 같습니다!


elderName = findMinAge(name, info);
olderName = findMaxAge(name, info);
n--;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while(n-- > 1) 처럼 한 줄로 합치는 방법도 있습니다!

Comment on lines +56 to +57
elderName = findMinAge(name, info);
olderName = findMaxAge(name, info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생년월일을 한번에 다 모아놓고 정렬하는 게 아니라 매번 받을 때마다 업데이트하는 방식이군요!! 좋은 방법인 것 같아요

public class BJ_7785{
public static void main(String[] args) {
int N = 0;
HashMap<String, String> hash=new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정렬을 위해서라면 TreeMap을 사용해 보는 것도 괜찮을 것 같습니다!

ArrayList<String> arr=new ArrayList<>();

for(String str: hash.keySet())
if(hash.get(str).equals("enter")) arr.add(str);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별로 상관없는 얘기일 수 있지만 두 문자열을 비교할 때 변수.equals("리터럴")보다 "리터럴".equals(변수)를 권장한다고 합니다! 왜냐면 변수는 null이 될 수 있기 때문에 equals 호출에 NPE가 발생할 수 있지만 리터럴은 그럴 경우가 없어서라고 하네요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants