Search Here

Sunday, July 12, 2015

UVa - 10101 ( Bangla Numbers Solution ) [ C & C++ Code ]

=>Try Yourself First. For help Scroll Down .

Clearance : The problem is Easy to understand but a much more Tricky . You know what to do but You can't find how to do ? I got 4 Wrong Answer & 1 Presentation Error verdict. I have checked more that 150 test cases for this problem . I will provide here a  list of test cases . Try those. Hopefully you will get an ACCEPTED verdict . Here's how you solve this problem : -

1)  Take an input which is less than 999999999999999 . Don't worry it will fit into a " long long int " data type .

2) Then you have to find the process of " kuti " , " lakh " , " hajar ", "shata" , " kuti", " lakh ", " hajar ", "shata" . Its upto you . I haven't any intention to destroy your creativity. 

3) The problem you will face greatly when you get the input like this ... 100000000000000 which is " 1 kuti kuti " in words but you will found " 1 kuti " . So to do that : -
i)  You will get the result of  " kuti " , " lakh " , " hajar ", "shata" , " kuti", " lakh ", " hajar ", "shata" by doing MOD of the N . Then check whether the MODulused number is less than 10000000 . Than print a " kuti " after printing the previous one . 
ii) Check the number is less than 10000000 when N is greater / equal than 10000000 .

Tip :  Take a good care of Spacing and Test Case number . Each and Every Output line will print with a case number with 4 column Right Justified . Print the "\n" once after printing the whole line . Take a good care of Corner Cases like - 0, 00001, 47488000034 etc. Try all those test I will provide at end of the Post . Spacing is most Important . Print the Space Before printing the integers . Data type should always be " long long int " if you don't use string .

Code :


#include<bits/stdc++.h>

using namespace std;

int main()
{
    long long int n ;
    int caseno=0;
    while(scanf("%lld", &n)==1)
    {
        printf("%4d.",++caseno);
        if(n==0) { puts(" 0");  continue; }
        if((n/100000000000000)!=0)
          { printf(" %lld kuti", n/100000000000000); n = n%100000000000000; if(n<10000000) printf(" kuti"); }
        if((n/1000000000000)!=0)
          { printf(" %lld lakh", n/1000000000000);  n = n%1000000000000; if(n<10000000) printf(" kuti");}
        if((n/10000000000)!=0)
          { printf(" %lld hajar", n/10000000000); n = n%10000000000; if(n<10000000) printf(" kuti");}
        if((n/1000000000)!=0)
          { printf(" %lld shata", n/1000000000); n = n%1000000000;  if(n<10000000) printf(" kuti");}
        if((n/10000000)!=0)
          { printf(" %lld kuti", n/10000000); n = n%10000000;  }
        if((n/100000)!=0)
          { printf(" %lld lakh", n/100000);  n = n%100000;}
        if((n/1000)!=0)
          { printf(" %lld hajar", n/1000); n = n%1000;  }
        if((n/100)!=0)
          { printf(" %lld shata", n/100); n = n%100;  }
        if(n!=0)
           printf(" %lld",n);

        printf("\n");
    }
    return 0;
}

***** The Test Cases are Here : CLICK HERE ******

=>Question or Need Help ?? Leave a Comment .

No comments:

Post a Comment