일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Notice
Recent Posts
Recent Comments
Link
Tags
- 경우의 수 자바
- 배열 순환 문제 공식
- 배열 순환 자바
- 펙토리얼
- 정보처리기사 필기
- 정처기 필기 벼락치기
- 숨어있는 숫자의 덧셈 (1) 자바
- string과 stringbuilder 성능 최적화
- 자바 팩토리얼
- 프로그래머스
- cursor 설치
- 피그마 썸네일
- 자바 합성수 찾기
- 티스토리챌린지
- 스프링부트 의존성 설정
- 오블완
- spring boot 배너 설정
- 스프링 부트 프로젝트 세팅
- cursor 우클릭 메뉴
- 정보처리기사 필기 벼락치기
- 프로그래머스 문자열 정렬하기(1)
- 소인수분해 구하는 공식
- 접속 url 출력
- 자바 소인수분해
- 왓챠피디아 클론 코딩
- 비전공자 정처기 필기
- 프로그래머스 공 던지기 게임
- 스프링 부트 배너 설정
- 배열 순환
- 비전공자 정보처리기사 필기
Archives
- Today
- Total
여름 언덕에서 배운 것
[0단계/2점]전국 대회 선발 고사 본문
import java.util.*;
class Solution {
public int solution(int[] rank, boolean[] attendance) {
Map<Integer,Integer> studentRanks = new HashMap<>();
for(int i=0; i< rank.length;i++){
if(attendance[i]){
studentRanks.put(rank[i],i); // 참여가 가능한 학생의 등수와, 반번호를 Map에 저장
}
}
// 참여 가능한 등수만 꺼내서 오름차순하여 배열로 만들어 준 다음에
List<Integer>keySet = new ArrayList<>(studentRanks.keySet());
Collections.sort(keySet);
int[] newRanking = keySet.stream().mapToInt(Integer::intValue).toArray();
// 등수에 해당하는 반 번호를 불러와 값을 곱해준다.
int answer = 0;
answer = 10000*(studentRanks.get(newRanking[0])) + 100 *(studentRanks.get(newRanking[1])) + (studentRanks.get(newRanking[2])) ;
return answer;
}
}
다른 사람 풀이
import java.util.ArrayList;
import java.util.TreeMap;
class Solution {
public int solution(int[] rank, boolean[] attendance) {
TreeMap<Integer, Integer> tree = new TreeMap<>();
for (int i = 0; i < rank.length; i++) {
if (attendance[i] == true) tree.put(rank[i], i);
}
ArrayList<Integer> list = new ArrayList<>();
for (Integer key : tree.keySet()) {
if (list.size() == 3) break;
list.add(tree.get(key));
}
return list.get(0) * 10000 + list.get(1) * 100 + list.get(2);
}
}
TreeMap은정렬된 상태를 유지 , 자동으로 key 값을 오름차순해준다
728x90
'가랑비에 옷 젖는 줄 모른다 💻 > 🌰코테문풀_꾸준히' 카테고리의 다른 글
[0단계/1점]그림확대 (0) | 2025.02.10 |
---|---|
[0단계/1점] 0 떼기 (0) | 2025.02.06 |
[0단계/1점] 뒤에서 5등까지 (0) | 2025.02.05 |
[0단계/1점] 배열의 길이에 따라 다른 연산하기 (0) | 2025.02.05 |
[0단계/3점] 문자열 묶기 (0) | 2025.02.05 |