tophbot  
                
               
                 
              
                  
                    November 5, 2022, 11:00am
                   
                   
              1 
               
             
            
              You have an unlimited number of cash notes of the following denominations: 1, 5, 10, 50, 100, 500. G…
Click here  to read the complete problem statement.
 
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
             
            
               
               
               
            
            
           
          
            
              
                Imran02  
                
               
              
                  
                    November 11, 2022,  2:58pm
                   
                   
              2 
               
             
            
              #include<stdio.h>
#include<math.h>
int main()
{
    int i,n,w=0,x=0,y=0,z=0,t;
    scanf("%d",&n);
    if(n>=500)
    {
        z=n/500;
        n=n%500;
    }
    if(n>=100 && n<500)
    {
        y=n/100;
        n=n%100;
    }
    if(n>=50 && n<100)
    {
        x=n/50;
        n=n%50;
    }
    if(n>=10 && n<50)
    {
        w=n/10;
        n=n%10;
    }
    if(n>=5 && n<10)
    {
        if(n==5)
        {
            printf("%d ",5);
        }
        else
        {
            t=n/5;
            n=n%5;
        }
    }
    if(n<5)
    {
        for(i=1;i<=n;i++)
            printf("%d ",1);
    }
    if(t<2)
    {
        for(i=1;i<=t;i++)
         {printf("%d ",5);}
    }
    if(w<=4)
    {
        for(i=1;i<=w;i++)
        {
            printf("%d ",10);
        }
    }
    if(x==1)
    {
        for(i=1;i<=x;i++)
        {
            printf("%d ",50);
        }
    }
    if(y<=4)
    {
        for(i=1;i<=y;i++)
        {
            printf("%d ",100);
        }
    }
    if(z<=20)
    {
        for(i=1;i<=z;i++)
        {
            printf("%d ",500);
        }
    }
    printf("\n");
    return 0;
}
 
What is the problem?wa in given test case.
             
            
               
               
              1 Like 
            
            
           
          
            
              
                hjr265  
                
               
              
                  
                    November 12, 2022,  2:44am
                   
                   
              3 
               
             
            
              @Imran02  Looks like you found the fix for your problem. Nice work!
             
            
               
               
               
            
            
           
          
            
              
                Imran02  
                
               
              
                  
                    November 12, 2022,  3:07am
                   
                   
              4 
               
             
            
              No,I didn’t fix.When I run the code in my compiler it works properly,but when i compile it in Toph it makes WA for given test case.
             
            
               
               
               
            
            
           
          
            
              
                hjr265  
                
               
              
                  
                    November 12, 2022,  3:09am
                   
                   
              5 
               
             
            
              
 Imran02:
 
if(t<2)
 
 
You are using t here in comparison. But you have never set the value of t. This will produce undefined behavior.
If you can explain your approach in words, I can help you guide through the fixes.
             
            
               
               
               
            
            
           
          
            
              
                Imran02  
                
               
              
                  
                    November 12, 2022,  5:13am
                   
                   
              6 
               
             
            
              OK,thank you.Now it is accepted.
             
            
               
               
              1 Like 
            
            
           
          
            
            
              Here is a simple solution in C++.
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
    int number;
    int five=0;
    int ten=0;
    int fifty=0;
    int hundred=0;
    int five_hundred=0;
    cin >> number;
    if(number/500>0){
        five_hundred=floor(number/500);
        number = number-(five_hundred*500);
    }
    if(number/100>0){
        hundred=floor(number/100);
        number = number-(hundred*100);
    }
    if(number/50>0){
        fifty=floor(number/50);
        number = number-(fifty*50);
    }
    if(number/10>0){
        ten=floor(number/10);
        number = number-(ten*10);
    }
    if(number/5>0){
        five=floor(number/5);
        number = number-(five*5);
    }
    for(int i=0;i<number;i++){
        cout<<1<<' ';
    }
    for(int i=0;i<five;i++){
        cout<<5<<' ';
    }
    for(int i=0;i<ten;i++){
        cout<<10<<' ';
    }
    for(int i=0;i<fifty;i++){
        cout<<50<<' ';
    }
    for(int i=0;i<hundred;i++){
        cout<<100<<' ';
    }
    for(int i=0;i<five_hundred;i++){
        cout<<500<<' ';
    }
    
}