SHARE
TWEET

Untitled

a guest May 16th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Find minimum number of currency notes and values that sum to given amount
  2. import java.util.*;
  3. public class MyClass {
  4.     public static void main(String args[]) {
  5.      
  6.       int[] a = {2000,500,200,100,50,20,10,5,1};
  7.       int[] b = new int[9];
  8.       int k = 2456;
  9.       for(int i=0;i<9&&k>0;i++){
  10.          
  11.          
  12.           if(k>=a[i]){
  13.               int q = k/a[i];
  14.               k = k - (q*a[i]);
  15.               b[i] = q;
  16.           }
  17.          
  18.          
  19.       }
  20.      
  21.       for(int i=0;i<9;i++){
  22.          
  23.          if(b[i]>0){
  24.               System.out.println(a[i]+"-"+b[i]);
  25.          }
  26.          
  27.       }
  28.      
  29.      
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top