You have x no. of 5 rupee coins and y no. of 1 rupee coins. You want to purchase an item for amount z. The shopkeeper wants you to provide exact change. You want to pay using minimum number of coins. How many 5 rupee coins and 1 rupee coins will you use? If exact change is not possible then display -1.

Question:
You have x no. of 5 rupee coins and y no. of 1 rupee coins. You want to purchase an item for amount z. The shopkeeper wants you to provide exact change. You want to pay using minimum number of coins. How many 5 rupee coins and 1 rupee coins will you use? If exact change is not possible then display -1.
Solution:

7 comments:

  1. 16th & 17th lines are incorrect I think soo...

    ReplyDelete
  2. IN JAVA:

    class Tester {
    public static void main(String[] args) {
    int noone = 9;
    int nofive =3*5;
    int nofivereqd = 0;
    int amtonereqd = 0;
    int total = nofive+noone;
    int amt = 21;

    if (amt>total) {
    System.out.println("-1");
    }

    else if (amt <= total) {
    nofivereqd = amt/5;
    System.out.println("The number of 5 notes required "+ nofivereqd );
    amtonereqd = amt%5;
    System.out.println("number of one required " + amtonereqd);
    }

    else {
    System.out.println("-1");
    }
    }
    }

    ReplyDelete
  3. If I have 10 1Rs note 1 5rs note, and amount to be paid is 12rs, then how what is out put of above program?

    ReplyDelete
  4. class Tester {
    public static void main(String[] args) {
    // Implement your code here
    int purchaseAmount = 19;
    int $1Notes = 3;
    int $5Notes = 3;
    int $1NotesNeeded = 0;
    int $5NotesNeeded = 0;

    $5NotesNeeded = purchaseAmount/5;
    $1NotesNeeded = purchaseAmount%5;

    if ($5NotesNeeded<=$5Notes && $1NotesNeeded<=$1Notes)
    {
    System.out.println("$5 notes needed = "+$5NotesNeeded);
    System.out.println("$1 notes needed = "+$1NotesNeeded);
    }
    else if ($5NotesNeeded>$5Notes && $1NotesNeeded<$1Notes)
    {
    $1NotesNeeded = purchaseAmount-$5Notes*5;
    $5NotesNeeded = $5Notes;
    System.out.println("$5 notes needed = "+$5NotesNeeded);
    System.out.println("$1 notes needed = "+$1NotesNeeded);
    }
    else
    System.out.println(-1);
    }
    }

    ReplyDelete

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...