일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 접근지시자
- 합병 정렬
- 바운디드 타입
- System.in
- docker
- raw 타입
- 자바할래
- throwable
- System.out
- Study Halle
- 람다식
- System.err
- 익명 클래스
- 함수형 인터페이스
- 제네릭 타입
- Switch Expressions
- junit 5
- 프리미티브 타입
- github api
- 상속
- 정렬
- 자바스터디
- auto.create.topics.enable
- 제네릭 와일드 카드
- 스파르타코딩클럽
- 로컬 클래스
- yield
- 항해99
- 브릿지 메소드
- annotation processor
Archives
- Today
- Total
코딩하는 털보
21.09.09 TIL 본문
백준 코드 퀴즈
2771번 부녀회장이 될테야
3중 for문으로 아파트 만들어 놓기
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static int[][] apt = new int[15][14];
public static void main(String[] args) throws IOException {
for (int i = 0; i < 14; i++) {
apt[0][i] = i+1;
}
for (int i = 1; i < apt.length; i++) {
apt[i][0] = 1;
for (int j = 1; j < apt[i].length; j++) {
for (int k = 0; k <= j; k++) {
apt[i][j] += apt[i-1][k];
}
}
}
int tests = Integer.parseInt(reader.readLine());
for (int i = 0; i < tests; i++) {
int k = Integer.parseInt(reader.readLine());
int n = Integer.parseInt(reader.readLine());
System.out.println(apt[k][n-1]);
}
}
}
2중 for문으로 아파트 만들어 놓기 - 당연히 더 빠름
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static int[][] apt = new int[15][14];
public static void main(String[] args) throws IOException {
for (int i = 0; i < 14; i++) {
apt[0][i] = i+1;
}
for (int i = 1; i < apt.length; i++) {
apt[i][0] = 1;
for (int j = 1; j < apt[i].length; j++) {
apt[i][j] = apt[i-1][j] + apt[i][j-1];
}
}
int tests = Integer.parseInt(reader.readLine());
for (int i = 0; i < tests; i++) {
int k = Integer.parseInt(reader.readLine());
int n = Integer.parseInt(reader.readLine());
System.out.println(apt[k][n-1]);
}
}
}
Comments