URI Online Judge | 1018 Banknotes (Solution)
Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1018
https://www.urionlinejudge.com.br/judge/en/problems/view/1018
URI Online Judge | 1018
Banknotes
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
In this problem you have to read an integer number and calculate the smallest possible number of notes in which the value may be decomposed. The notes are of 100, 50, 20, 10, 5, 2 e 1. Print the value read and the list of notes.
Input
The input file contain an integer number N (0 < N < 1000000).
Output
Print the read number and the minimum quantity of each necessary banknotes, like as the given example. Do not forget to print the end line after each line, otherwise you will get “Presentation Error”.
Sample Input | Sample Output |
576 | 576 5 nota(s) de R$ 100,00 1 nota(s) de R$ 50,00 1 nota(s) de R$ 20,00 0 nota(s) de R$ 10,00 1 nota(s) de R$ 5,00 0 nota(s) de R$ 2,00 1 nota(s) de R$ 1,00 |
11257 | 11257 112 nota(s) de R$ 100,00 1 nota(s) de R$ 50,00 0 nota(s) de R$ 20,00 0 nota(s) de R$ 10,00 1 nota(s) de R$ 5,00 1 nota(s) de R$ 2,00 0 nota(s) de R$ 1,00 |
503 | 503 5 nota(s) de R$ 100,00 0 nota(s) de R$ 50,00 0 nota(s) de R$ 20,00 0 nota(s) de R$ 10,00 0 nota(s) de R$ 5,00 1 nota(s) de R$ 2,00 1 nota(s) de R$ 1,00 |
Solution:
#include <stdio.h>
int
main() {
int
d[] = {100, 50, 20, 10, 5, 2, 1};
int
n, t = 0;
scanf
(
"%d"
, &n);
printf
(
"%d\n"
, n);
do
{
printf
(
"%d nota(s) de R$ %d,00\n"
, n / d[t], d[t]);
if
(n >= d[t])
n -= d[t] * (n / d[t]);
}
while
(d[t++] != 1);
return
0;
}
Beautiful
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete#include
ReplyDeleteint main() {
int a,b,c,d,e,f,g;
scanf("%d",&a);
printf("%d",a);
b = a%100;
c = b%50;
d = c%20;
e = d%10;
f = e%5;
g = f%2;
printf("%d nota(s) de R$ 100,00\n%d nota(s) de R$ 50,00\n%d nota(s) de R$ 20,00\n%d nota(s) de R$ 10,00\n%d nota(s) de R$ 5,00\n%d nota(s) de R$ 2,00\n%d nota(s) de R$ 1,00\n",a/100,b/50,c/20,d/10,e/5,f/2,g/1);
return 0;
}
why this solve is showing 20% wrong answer?
You should insert a \n in very first printf function. :)
Delete#include
Deleteint main(void)
{
int i,j,n;
int a[7]={100,50,20,10,5,2,1};
int b[7];
scanf("%d",&n);
printf("%d\n",n);
for(i=0;i<7;i++){
b[i]=n/a[i];
n=n%a[i];
}
for(j=0;j<7;j++){
printf("%d nota(s) de R$ %d,00\n",b[j],a[j]);
}
return 0;
}
this is compilation error but why...?
Deletei guess that is rigt.
import java.util.Scanner;
ReplyDeletepublic class Main {
public static void main(String[] args) {
int taka;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
int m;
Scanner input = new Scanner(System.in);
taka = input.nextInt();
if(taka > 0 || taka <1000000)
{
a = taka / 100;
b = taka % 100;
c = b / 50;
d = b % 50;
e = d / 20;
f = d % 20;
g = f / 10;
h = f % 10;
i = h /5;
j = h % 5;
k = j / 2;
l = j % 2;
m = l / 1;
System.out.printf("%d nota(s) de R$ 100.00\n", a);
System.out.printf("%d nota(s) de R$ 50.00\n", c);
System.out.printf("%d nota(s) de R$ 20.00\n", e);
System.out.printf("%d nota(s) de R$ 10.00\n", g);
System.out.printf("%d nota(s) de R$ 5.00\n", i);
System.out.printf("%d nota(s) de R$ 2.00\n", k);
System.out.printf("%d nota(s) de R$ 1.00\n", m);
}
}
}
why i have seen 90% wrong answer??
int m=1 , n=2
ReplyDeletefor(j=1 ;j<=2 ;j+1)
{m=m+1;
n=n*j;
printf("%d\t %d\t" , m,n,);
#include
ReplyDeleteint main()
{
int N,m,n,o,p,q,r,s;
scanf("%d",&N);
m=N/100;
n=(N%100)/50;
o=((N%100)%50)/20;
p=(((N%100)%50)%20)/10;
q=((((N%100)%50)%20)%10)/5;
r=(((((N%100)%50)%20)%10)%5)/2;
s=((((((N%100)%50)%20)%10)%5)%2)/1;
printf("%d nota(s) de R$ 100,00\n%d nota(s) de R$ 50,00\n%d nota(s) de R$ 20,00\n%d nota(s) de R$ 10,00\n%d nota(s) de R$ 5,00\n%d nota(s) de R$ 2,00\n%d nota(s) de R$ 1,00\n",m,n,o,p,q,r,s);
return 0;
}
wrong 100%.....but why.
#include
ReplyDeleteint main()
{
int N,A,B,C,D,E,F,G;
scanf("%d",&N);
if(0<N && N<1000000)
{
A=N/100;
B=N%100/50;
C=N%100%50/20;
D=N%100%50%20/10;
E=N%100%50%20%10/5;
F=N%100%50%20%10%5/2;
G=N%100%50%20%10%5%2/1;
printf("%d nota(s) de R$ 100,00\n%d nota(s) de R$ 50,00\n%d nota(s) de R$ 20,00\n%d nota(s) de R$ 10,00\n%d nota(s) de R$ 5,00\n%d nota(s) de R$ 2,00\n%d nota(s) de R$ 1,00\n",A,B,C,D,E,F,G);
}
return 0;
}
import java.util.Scanner;
ReplyDeletepublic class Main {
public static void main(String[] args) {
int givenbValue;
Scanner scan = new Scanner(System.in);
givenbValue = scan.nextInt();
int fiftyTaka = givenbValue % 100;
int hundredValue = givenbValue / 100;
System.out.println(hundredValue + " nota(s) de R$ 100,00");
int twentyTaka = fiftyTaka % 50;
fiftyTaka = fiftyTaka / 50;
System.out.println(fiftyTaka + " nota(s) de R$ 50,00");
int tenTaka = twentyTaka % 20;
twentyTaka = twentyTaka / 20;
System.out.println(twentyTaka + " nota(s) de R$ 20,00");
int fiveTaka = tenTaka % 10;
tenTaka = tenTaka / 10;
System.out.println(tenTaka + " nota(s) de R$ 10,00");
int twoTaka = fiveTaka % 5;
fiveTaka = fiveTaka / 5;
System.out.println(fiveTaka + " nota(s) de R$ 5,00");
int oneTaka = twoTaka % 2;
twoTaka = twoTaka / 2;
System.out.println(twoTaka + " nota(s) de R$ 2,00");
oneTaka = oneTaka / 1;
System.out.println(oneTaka + " nota(s) de R$ 1,00");
}
}
#include
ReplyDeleteusing namespace std;
int main()
{
int n , a , b , c , d , e , f , g ;
cin>>n;
if (n>0 && n<1000000)
{
a=n/100;
b=n%100/50;
c=n%100%50/20;
d=n%100%50%20/10;
e=n%100%50%20%10/5;
f=n%100%50%20%10%5/2;
g=n%100%50%20%10%5%2/1;
cout<<n<<endl;;
cout<<a<<" nota(s) de R$ 100,00"<<endl;
cout<<b<<" nota(s) de R$ 50,00"<<endl;
cout<<c<<" nota(s) de R$ 20,00"<<endl;
cout<<d<<" nota(s) de R$ 10,00"<<endl;
cout<<e<<" nota(s) de R$ 5,00"<<endl;
cout<<f<<" nota(s) de R$ 2,00"<<endl;
cout<<g<<" nota(s) de R$ 1,00"<<endl;
}
return 0;
}