> For the complete documentation index, see [llms.txt](https://xtecna.gitbook.io/solucoes-da-beecrowd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xtecna.gitbook.io/solucoes-da-beecrowd/iniciante/1021-notas-e-moedas.md).

# 1021 - Notas e Moedas

Um problema bastante parecido com o 1018 - Cédulas, mas com algumas coisas a mais.

## Descrição

{% embed url="<https://www.urionlinejudge.com.br/judge/pt/problems/view/1021>" %}

## Solução

Para entender o raciocínio para resolver este problema, consulte [1018 - Cédulas](/solucoes-da-beecrowd/iniciante/1018-cedulas.md).

Entretanto, temos alguns detalhes aqui: é um pouco problemático obter o resto da divisão para números não inteiros. Por isso, eu decidi que seria uma boa multiplicar por 100 todos os valores envolvidos para me certificar de que só faria manipulação com números inteiros. Também simplifiquei o código para evitar repetições, fazendo com que na hora de imprimir os valores, também seja necessário dividir por 100.

{% tabs %}
{% tab title="C99" %}

```c
#include <stdio.h>

int main(){
    int notas[] = {10000, 5000, 2000, 1000, 500, 200};
    int moedas[] = {100, 50, 25, 10, 5, 1};
    int reais, centavos;

    scanf("%d.%d", &reais, &centavos);
    reais = 100 * reais + centavos;

    printf("NOTAS:\n");
    for(int i = 0; i < 6; ++i){
        printf("%d nota(s) de R$ %.2lf\n", reais/notas[i], notas[i]/100.0);
        reais %= notas[i];
    }

    printf("MOEDAS:\n");
    for(int i = 0; i < 6; ++i){
        printf("%d moeda(s) de R$ %.2lf\n", reais/moedas[i], moedas[i]/100.0);
        reais %= moedas[i];
    }

    return 0;
}
```

{% endtab %}

{% tab title="C++17" %}

```cpp
#include <cstdio>

int main(){
    int notas[] = {10000, 5000, 2000, 1000, 500, 200};
    int moedas[] = {100, 50, 25, 10, 5, 1};
    int reais, centavos;

    scanf("%d.%d", &reais, &centavos);
    reais = 100 * reais + centavos;

    printf("NOTAS:\n");
    for(int i = 0; i < 6; ++i){
        printf("%d nota(s) de R$ %.2lf\n", reais/notas[i], notas[i]/100.0);
        reais %= notas[i];
    }

    printf("MOEDAS:\n");
    for(int i = 0; i < 6; ++i){
        printf("%d moeda(s) de R$ %.2lf\n", reais/moedas[i], moedas[i]/100.0);
        reais %= moedas[i];
    }

    return 0;
}
```

{% endtab %}

{% tab title="JavaScript 12.18" %}

```javascript
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var lines = input.split("\n");

let [reais, centavos] = lines.shift().trim().split('.').map((x) => parseInt(x));
let valor = 100 * reais + centavos;

notas = [10000, 5000, 2000, 1000, 500, 200];
moedas = [100, 50, 25, 10, 5, 1];

console.log("NOTAS:");
notas.forEach((nota) => {
  console.log(`${Math.floor(valor/nota).toFixed(0)} nota(s) de R$ ${(nota/100).toFixed(2)}`);
  valor %= nota;
});

console.log("MOEDAS:");
moedas.forEach((moeda) => {
  console.log(`${Math.floor(valor/moeda).toFixed(0)} moeda(s) de R$ ${(moeda/100).toFixed(2)}`);
  valor %= moeda;
});

```

{% endtab %}

{% tab title="Python 3.9" %}

```python
reais, centavos = [int(x) for x in input().strip().split('.')]
reais = reais * 100 + centavos

notas = [10000, 5000, 2000, 1000, 500, 200]
moedas = [100, 50, 25, 10, 5, 1]

print("NOTAS:")
for nota in notas:
    print(f"{reais//nota} nota(s) de R$ {(nota/100):.2f}")
    reais %= nota

print("MOEDAS:")
for moeda in moedas:
    print(f"{reais//moeda} moeda(s) de R$ {(moeda/100):.2f}")
    reais %= moeda
```

{% endtab %}
{% endtabs %}
