일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- javageneric
- Open EntityManager
- 데이터베이트h2
- dockercmd
- JPA프록시
- springbootproxy
- JPAmapping
- jpa
- gitinitial
- springboot기본설정
- 제이피큐엘쿼리
- 임베디드타입
- sql
- MySqlType
- 스프링부트
- 스프링부트기본설정
- JDBC connection pool
- spring
- Git
- JPAproxy
- 에이치투데이터베이스
- springbootH2
- JPA Hint & Lock
- 이해와 원리
- OSIV
- embededtype
- httppie
- 자바제너릭
- jpqlquery
- JPA값타입
Archives
- Today
- Total
빡코
[ 과제]백준_ 11047번_동전0 본문
https://www.acmicpc.net/problem/11047
11047번: 동전 0
첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수)
www.acmicpc.net
풀긴 풀엇는디 ㅋㅋㅋ 런타임 에러다 ...
런타임에러1
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int k= sc.nextInt();
int[] coin = new int[n];
for(int i =0;i<n;i++) {
coin[i]=sc.nextInt();
}
int cnt = 0;
for(int i=9;i>=0;i--) {
if(k!=0&&k>=coin[i]) {
k-=coin[i];
i+=1;
cnt+=1;
}
}
System.out.println(cnt);
sc.close();
}
}
런타임 에러2
package algorithmStudy;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int k= sc.nextInt();
int[] coin = new int[n];
for(int i =0;i<n;i++) {
coin[i]=sc.nextInt();
}
int cnt = 0;
for(int i=9;i>=0;i--) {
if(k>=coin[i]&&k!=0) {
cnt+=k/coin[i];
k=k%coin[i];
}
}
System.out.println(cnt);
sc.close();
}
}
'Algorithm' 카테고리의 다른 글
[과제]프로그래머스_두 정수 사이의 합 (0) | 2020.01.02 |
---|---|
[과제] 설명 준비해오기1 (0) | 2020.01.02 |
[과제]백준_ 10872번 _팩토리얼 (0) | 2020.01.02 |
[스터디] 프로그래머스_레벨1_2016년 ( 요일맞추기) (0) | 2020.01.02 |
알고리즘에 대하여 (0) | 2020.01.02 |