Saturday 16 January 2016

Solution of URI 1021 :: Banknotes and Coins


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    double A,D,E;
    scanf ("%lf",&A);
    int N,a,b,c,d,e,f,g,h,i,j,k,l,B,m,n,o,p,q,r,s,t,u;
    N=A;
    a=N/100;
    b=N%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;

    E=A*100;
    B=(int) E;
    m=B%100;
    n=m/50;
    o=m%50;
    p=o/25;
    q=o%25;
    r=q/10;
    s=q%10;
    t=s/5;
    u=s%5;

    printf ("NOTAS:\n");
    printf ("%d nota(s) de R$ 100.00\n",a);
    printf ("%d nota(s) de R$ 50.00\n",c);
    printf ("%d nota(s) de R$ 20.00\n",e);
    printf ("%d nota(s) de R$ 10.00\n",g);
    printf ("%d nota(s) de R$ 5.00\n",i);
    printf ("%d nota(s) de R$ 2.00\n",k);
    printf ("MOEDAS:\n");
    printf ("%d moeda(s) de R$ 1.00\n",l);
    printf ("%d moeda(s) de R$ 0.50\n",n);
    printf ("%d moeda(s) de R$ 0.25\n",p);
    printf ("%d moeda(s) de R$ 0.10\n",r);
    printf ("%d moeda(s) de R$ 0.05\n",t);
    printf ("%d moeda(s) de R$ 0.01\n",u);

    return 0;
}

15 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Puts cara, eu fiz em python mas não esta aceitando :(. Esta batendo certinho, mas fala que esta errado...

    ReplyDelete
  3. Puts cara, eu fiz em python mas não esta aceitando :(. Esta batendo certinho, mas fala que esta errado...

    ReplyDelete
  4. por acaso da wrong answer 10% ?
    o meu ta a mesma coisa. bate tudo mas nao aceita

    ReplyDelete
    Replies
    1. por acaso da wrong answer 10% ?
      o meu ta a mesma coisa. bate tudo mas nao aceita (mesma coisa comigo) "java 8"

      Delete
    2. Fiz em python 3, a saida está igual o pedido.. e tbm está dando wrong answer 10%... desisti e fiz em C ai resolveu.. site deve ta com algum bug em especifico com python e java sei la

      Delete
  5. GALERA ALGUEM SABE QUAL SERIA O PROBLEMA DO MEU CODIGO ESTOU COM 10% DE ERRO!!


    #include

    int main() {

    int n, m;
    scanf("%d.%d", &n, &m);

    printf("NOTAS:\n%d nota(s) de R$ 100.00\n", n/100);
    printf("%d nota(s) de R$ 50.00\n", n%100/50);
    printf("%d nota(s) de R$ 20.00\n", n%100%50/20);
    printf("%d nota(s) de R$ 10.00\n", n%100%50%20/10);
    printf("%d nota(s) de R$ 5.00\n", n%100%50%20%10/5);
    printf("%d nota(s) de R$ 2.00\n", n%100%50%20%10%5/2);

    printf("MOEDAS:\n%d moeda(s) de R$ 1,00\n", n%100%50%20%10%5%2);
    printf("%d moeda(s) de R$ 0.50\n", m%100/50);
    printf("%d moeda(s) de R$ 0.25\n", m%100%50/25);
    printf("%d moeda(s) de R$ 0.10\n", m%100%50%25/10);
    printf("%d moeda(s) de R$ 0.05\n", m%100%50%25%10/5);
    printf("%d moeda(s) de RS 0.01\n", m%100%50%25%10%5);


    return 0;
    }

    ReplyDelete
    Replies
    1. ele te manda um float e vc ta lendo somente a parte inteira

      Delete
    2. foi mal, nao prestei atenção no scanf -.-"
      printf("MOEDAS:\n%d moeda(s) de R$ 1,00\n", n%100%50%20%10%5%2);
      o 1,00 acho q é 1.00

      Delete
  6. Quando uso 576.43 como entrada, o programa só conta 2 moedas de 1 centavo, não entendo o pq.

    #include

    int main(int argc, char **argv)
    {
    float valor, cedulas[6]={100.00, 50.00, 20.00, 10.00, 5.00, 2.00}, moedas[6]={1.00, 0.50, 0.25, 0.10, 0.05, 0.01};
    int notas,i, quantiMoedas;

    scanf("%f", &valor);

    printf("NOTAS:\n");
    i=0;

    while(i < 6){
    notas = valor / cedulas[i];
    printf("%d nota(s) de R$ %1.2f\n", notas, cedulas[i]);
    valor -= (cedulas[i] * notas);
    i++;
    }

    i=0;

    printf("MOEDAS:\n");
    while(i < 6){
    quantiMoedas = valor / moedas[i];
    printf("%d moeda(s) de R$ %1.2f\n", quantiMoedas, moedas[i]);
    valor -= (moedas[i] * quantiMoedas);
    i++;
    }

    return 0;
    }

    ReplyDelete
    Replies
    1. É pq vc ta usando o "float" para da entrada em um número com 2 casas decimais, quando temos números igual a esse na leitura usamos o "double" para declarar a variável.

      Obs: Estava com esse mesmo problema, fiz isso e deu certo.

      Delete
  7. código funciona em todos os casos de teste mas me da WA 10%,não da para entender...
    float n;
    int valor,inicio,resto;
    scanf("%f", &n);
    valor=n;
    inicio=valor;
    printf("NOTAS:\n%d nota(s) de R$ 100.00\n",valor/100);
    valor=valor%100;
    printf("%d nota(s) de R$ 50.00\n",valor/50);
    valor=valor%50;
    printf("%d nota(s) de R$ 20.00\n",valor/20);
    valor=valor%20;
    printf("%d nota(s) de R$ 10.00\n",valor/10);
    valor=valor%10;
    printf("%d nota(s) de R$ 5.00\n",valor/5);
    valor=valor%5;
    printf("%d nota(s) de R$ 2.00\n",valor/2);
    valor=valor%2;
    printf("MOEDAS:\n%d moeda(s) de R$ 1.00\n",valor);
    resto=(n*100)-(inicio*100)+0.01;
    printf("%d moeda(s) de R$0.50\n",resto/50);
    resto=resto%50;
    printf("%d moeda(s) de R$0.25\n",resto/25);
    resto=resto%25;
    printf("%d moeda(s) de R$0.10\n",resto/10);
    resto=resto%10;
    printf("%d moeda(s) de R$0.05\n",resto/5);
    resto=resto%5;
    printf("%d moeda(s) de R$0.01\n",resto);
    return 0;

    ReplyDelete
  8. Where's the error? (Onde está o erro?)

    Language: C++

    #include

    using namespace std;

    int main()
    {
    double valor, valores_moeda[12] = {100,50,20,10,5,2,1,0.50,0.25,0.10,0.05,0.01};
    int i, valor_decomposto, quant_moedas[12] = {0};
    string texto_moedas[12] = {"100.00","50.00","20.00","10.00","5.00","2.00",
    "1.00","0.50","0.25","0.10","0.05","0.01"};

    cin >> valor;

    for(i = 0; i < 12; i++)
    {
    valor_decomposto = valor / valores_moeda[i];
    quant_moedas[i] = valor_decomposto;
    valor = valor - (valores_moeda[i] * (double) valor_decomposto);

    if(i==0)
    cout << "NOTAS:" << endl;

    if(i==6)
    cout << "MOEDAS:" << endl;

    if(i<6)
    cout << quant_moedas[i] << " nota(s) de R$ " << texto_moedas[i] << endl;
    else
    cout << quant_moedas[i] << " moeda(s) de R$ " << texto_moedas[i] << endl;
    }

    return 0;
    }

    ReplyDelete
  9. for URI 1021

    when you approach to find the number of moedas , then
    just you have to do the little this to avoid 10% / 20% error ALTHOUGH YOUR ANSWER WAS CORRECT BUT NOT ACCEPTED BY URI COMPILER
    N =576.73.
    int M = (int)N; // M= 576
    float O = N-M; // O = .72922 *** problem is here***
    int I = (int)O*100; //I = 72 but we took .73
    M= (int) O * 1000; // M = 729
    if ( M % 10 > = 5 )
    { I++; }
    // now you print example
    int ft= i/50;


    printf( "%d moeda(s) de R$ 0.50\n",FT);
    ft= i%50/25;
    printf( "%d moeda(s) de R$ 0.25\n",FT);
    ft= i%50%25/10;
    printf( "%d moeda(s) de R$ 0.10\n",ft);
    ft= i%50%25%10/5;




    ReplyDelete

Note: only a member of this blog may post a comment.