URI 1018 Solve

Solve of URI 1018 (Banknotes) in C & C++

How to solve:
1. In this problem, we need to calculate smallest possible banknotes of a given amount.

2. Input N is an integer value as amount ( 0 < N < 1000000).
3. We need to divide given amount, as R$ 100, 50, 20, 10, 5, 2 and 1 notes.
4. After taking input, we need to calculate total number of R$ 100 note(s) needed and print as "Number_of_Notes nota(s) de R$ 100,00" format.
5. Then calculate total number of R$ 50 note(s) needed and print as "Number_of_Notes nota(s) de R$ 50,00" format.

6. Then calculate total number of R$ 20 note(s) needed and print as "Number_of_Notes nota(s) de R$ 20,00" format.
7. Then calculate total number of R$ 10 note(s) needed and print as "Number_of_Notes nota(s) de R$ 20,00" format.
8. Then calculate total number of R$ 5 note(s) needed and print as "Number_of_Notes nota(s) de R$ 5,00" format.
9. Then calculate total number of R$ 2 note(s) needed and print as "Number_of_Notes nota(s) de R$ 2,00" format.
10. And rest is printed as "Number_of_Notes nota(s) de R$ 1,00" format.
See sample input and output for better understanding with printing output.
Go through problem description and see my solution for clear concept. Thanks. :)


Solution in C:
//URI online judge 1018 solution in C
//This solution is made by Mehedi Hasan Kajol


#include<stdio.h>
int main(void){
    long int input,temp, n_100,n_50,n_20,n_10,n_5,n_2;
    scanf("%ld",&input);
    printf("%ld\n",input);


    n_100=input/100;
    temp=input%100;
    printf("%ld nota(s) de R$ 100,00\n",n_100);


    n_50=temp/50;
    temp=temp%50;
    printf("%ld nota(s) de R$ 50,00\n",n_50);


    n_20=temp/20;
    temp=temp%20;
    printf("%ld nota(s) de R$ 20,00\n",n_20);


    n_10=temp/10;
    temp=temp%10;
    printf("%ld nota(s) de R$ 10,00\n",n_10);


    n_5=temp/5;
    temp=temp%5;
    printf("%ld nota(s) de R$ 5,00\n",n_5);


    n_2=temp/2;
    temp=temp%2;
    printf("%ld nota(s) de R$ 2,00\n",n_2);


    printf("%ld nota(s) de R$ 1,00\n",temp);
    return 0;
}



Solution in C++:
//URI online judge 1018 solution in C++
//This solution is made by Mehedi Hasan Kajol


#include<iostream>

using namespace std;
int main(void){
    long int input,temp, n_100,n_50,n_20,n_10,n_5,n_2;

    cin >> input ;
    cout << input <<endl;

    n_100=input/100;
    temp=input%100;

    cout << n_100 <<" nota(s) de R$ 100,00" <<endl;

    n_50=temp/50;
    temp=temp%50;
    
cout << n_50 <<" nota(s) de R$ 50,00" <<endl;

    n_20=temp/20;
    temp=temp%20;
    
cout << n_20 <<" nota(s) de R$ 20,00" <<endl;

    n_10=temp/10;
    temp=temp%10;
    
cout << n_10 <<" nota(s) de R$ 10,00" <<endl;

    n_5=temp/5;
    temp=temp%5;
    
cout << n_5 <<" nota(s) de R$ 5,00" <<endl;

    n_2=temp/2;
    temp=temp%2;
    
cout << n_2 <<" nota(s) de R$ 2,00" <<endl;

    cout << temp <<" nota(s) de R$ 1,00" <<endl;
    return 0;



Post a Comment

Previous Post Next Post