728x90
반응형
백준
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
- 오늘의 학습 키워드 : stream
- 공부한 내용 본인의 언어로 정리하기
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine()); // 사람 수
String[] input = br.readLine().split(" "); // 입력 값(인출 소요 시간)
List<Integer> list = new ArrayList<>(); // 인출 소요 시간
for (int i=0; i<N; i++) list.add(Integer.parseInt(input[i]));
Collections.sort(list);
int sum = 0;
for (int i=0; i<list.size(); i++) {
sum += list.get(i);
list.set(i, sum);
}
int result = list.stream()
.mapToInt(Integer::intValue)
.sum();
System.out.println(result);
}
}
- 오늘의 회고 : stream 배우고 이제 적용할 수 있다! stream을 복습할 수 있는 계기가 되었다 :)
99클럽 1기를 수강하면서 작성한 글입니다.
728x90
반응형
'Blog > Education' 카테고리의 다른 글
99클럽 코테 스터디 19일차 TIL + DP (0) | 2024.04.12 |
---|---|
99클럽 코테 스터디 18일차 TIL + map (0) | 2024.04.11 |
99클럽 코테 스터디 16일차 TIL + DP 리팩토링 (0) | 2024.04.09 |
99클럽 코테 스터디 15일차 TIL + DP (0) | 2024.04.08 |
99클럽 코테 스터디 14일차 TIL + Map key 사전순 정렬 (0) | 2024.04.07 |
댓글