(URI) Cédulas - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int dinheiro = leitor(br);
int dif = 0;
int cem = dinheiro/100;
dif = (dinheiro-cem*100);
int cinquenta = dif/50;
dif -= cinquenta*50;
int vinte = dif/20;
dif -= vinte*20;
int dez = dif/10;
dif -= dez*10;
int cinco = dif/5;
dif -= cinco*5;
int dois = dif/2;
dif -= dois*2;
int um = dif;
System.out.println(dinheiro);
System.out.println(cem + " nota(s) de R$ 100,00");
System.out.println(cinquenta + " nota(s) de R$ 50,00");
System.out.println(vinte + " nota(s) de R$ 20,00");
System.out.println(dez + " nota(s) de R$ 10,00");
System.out.println(cinco + " nota(s) de R$ 5,00");
System.out.println(dois + " nota(s) de R$ 2,00");
System.out.println(um + " nota(s) de R$ 1,00");
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9')
break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9')
break;
}
return resp;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int dinheiro = leitor(br);
int dif = 0;
int cem = dinheiro/100;
dif = (dinheiro-cem*100);
int cinquenta = dif/50;
dif -= cinquenta*50;
int vinte = dif/20;
dif -= vinte*20;
int dez = dif/10;
dif -= dez*10;
int cinco = dif/5;
dif -= cinco*5;
int dois = dif/2;
dif -= dois*2;
int um = dif;
System.out.println(dinheiro);
System.out.println(cem + " nota(s) de R$ 100,00");
System.out.println(cinquenta + " nota(s) de R$ 50,00");
System.out.println(vinte + " nota(s) de R$ 20,00");
System.out.println(dez + " nota(s) de R$ 10,00");
System.out.println(cinco + " nota(s) de R$ 5,00");
System.out.println(dois + " nota(s) de R$ 2,00");
System.out.println(um + " nota(s) de R$ 1,00");
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9')
break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9')
break;
}
return resp;
}
}
Comments
Post a Comment