SMALLEST NUMBER OF NOTES (FLOW005): Codechef solution in C++

    

SMALLEST NUMBER OF NOTES

Problem Code: FLOW005


Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.
If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.

Input Format

The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.

Output Format

For each test case, display the smallest number of notes that will combine to give N, in a new line.

Constraints

  •  T  1000
  •  N  1000000

Sample Input 1 

3 
1200
500
242

Sample Output 1 

12
5
7

Explanation

Test Case 1: There are 8 games remaining. Out of these 8 games, if RCB wins 2 games, loses 4 games and draws the remaining 2 games they will have a total of 10 points, this shows that it is possible for RCB to qualify for the playoffs.

Note: There can be many other combinations which will lead to RCB qualifying for the playoffs.

Test Case 2: There is no way such that RCB can qualify for the playoffs.

Test Case 3: If RCB wins all their remaining games, they will have end up with 8 points. (4+22=8), hence it is possible for them to qualify for the playoffs.

. . .

Solution in C++.


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;
	while(n--) {
	    int a;
	    cin >> a;
	    int count = 0;

	   // Count for 100
	    count += a /100;
	    a %= 100;

	   // Count for 50
	    count += a /50;
	    a %= 50;

	   // Count for 10
	    count += a /10;
	    a %= 10;

	   // Count for 5
	    count += a /5;
	    a %= 5;

	   // Count for 2
	    count += a /2;
	    a %= 2;

	   // Count for 1
	    count += a /1;
	    a %= 1;

	    cout << count  << endl;
	    
	}
	return 0;
}




Try Solution On The C-Playground : https://bit.ly/3Lb9uFV

Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C