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 {
- // 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 void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double change = Double.parseDouble(scan.nextLine());
- long totalCoins = 0;
- for (int i = 0; i < 3; i++) {
- /* Add coins:
- * 2, 1 leva (i = 0)
- * 20, 10 cents (i = 1)
- * 2, 1 cents (i = 2)
- */
- // The bitwise '& 1' checks for odd digit
- totalCoins += ((long) change / 2) + ((long) change & 1);
- change *= 10; // Get the next digit
- // Add coins: 50, 5 cents (i < 2)
- if (change % 10 >= 5 && i < 2) {
- totalCoins++;
- change -= 5;
- }
- // Truncate the front digits
- change = Double.parseDouble(getCSharpDouble(((change * 10) % 100) / 10));
- }
- System.out.println(totalCoins);
- }
- }
Add Comment
Please, Sign In to add comment