Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Project: Exam_07_January_2018 - created by borkins on 2018-02-05.
- */
- import java.util.Scanner;
- public class _06a_Coins {
- public static double n;
- // Formatting Java Double to C# Double
- public static String getCSharpDouble(double number) {
- StringBuilder sb = new StringBuilder();
- String str = "" + number;
- char sp = new java.text.DecimalFormatSymbols().getDecimalSeparator();
- int len = (str.length() > 15) ? 15 : str.length();
- for (int i = 0; i < len; i++) {
- sb.append((str.charAt(i) != sp) ? '#' : sp);
- }
- return new java.text.DecimalFormat("" + sb).format(number);
- }
- public static long count(int coinValue) {
- long coins = (long) Double.parseDouble(getCSharpDouble(n / coinValue));
- n = (long) Double.parseDouble(getCSharpDouble(n - coins * coinValue));
- return coins;
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- n = Double.parseDouble(scan.nextLine()) * 100.0;
- long totalCoins = 0;
- totalCoins += count(200);
- totalCoins += count(100);
- totalCoins += count(50);
- totalCoins += count(20);
- totalCoins += count(10);
- totalCoins += count(5);
- totalCoins += count(2);
- totalCoins += count(1);
- System.out.println(totalCoins);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement