Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[04주차 박상우] 거스름돈 #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pswoo0323
Copy link
Contributor

@pswoo0323 pswoo0323 commented Nov 10, 2023

🔎 문제 소개

🖊️ 풀이

  • 시간 복잡도: $O(N)$
  • 입력의 크기: $ 0<= N < 1000 $

-->
처음에 열심히 짰지만 시간초과가 나왔다.
그래서 다른건 건드리지 않고 배열을 사용해 수정하니 다행히 정상적으로 출력이 되었다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//거스름돈 시간초과 코드
public class BOJ_5585_excesstime {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int N = Integer.parseInt(br.readLine());
    int change = 0;
    int num = 0;
    int paymoney = 1000 - N;

    while (paymoney > 0) {
        if (paymoney / 500 > 0) {
            change = paymoney / 500;
            paymoney %= 500;
            num += change;
        } else if (paymoney / 100 > 0) {
            change = paymoney / 100;
            paymoney = paymoney % 100;
            num += change;
        } else if (paymoney / 50 > 0) {
            change = paymoney / 50;
            paymoney = paymoney % 50;
            num += change;
        } else if (paymoney / 10 > 0) {
            change = paymoney / 10;
            paymoney = paymoney % 10;
            num += change;
        } else if (paymoney / 5 > 0) {
            change = paymoney / 5;
            paymoney = paymoney % 5;
            num += change;
        } else{
            change = paymoney;
            num += change;
        }
    }
    System.out.println(num);
}

}
-->

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.

1 participant