Page 7 of 7

Re: 465 - Overflow

Posted: Sat Aug 23, 2014 8:38 pm
by Rika71
cant get ac. please help.

Code: Select all

got ac


Re: 465 - Overflow

Posted: Mon Aug 25, 2014 8:23 pm
by lighted
First you should check I/O posted in this thread. One example
Input
2147483647 * 1
2147483647 + 1
0 * 1000000000000
2147483648 * 0

Output
2147483647 * 1
2147483647 + 1
result too big
0 * 1000000000000
second number too big
2147483648 * 0
first number too big
Your output

Code: Select all

2147483647 * 1
2147483647 + 1
result too big
0 * 1000000000000
second number too big
result too big
2147483648 * 0
first number too big
result too big

Re: 465 - Overflow

Posted: Tue Aug 26, 2014 1:53 pm
by Rika71
thanks for replying, lighted.

Re: 465 - Overflow

Posted: Tue Sep 16, 2014 5:12 pm
by Shahidul.CSE
I have some confusion about this problem, such as:
1) Does input contain any negative integer? Though problem statements said, "consisting of two non-negative integer and an operator", but many gave inputs with negative number.
2) Does the input contain only one space after first number and after operator sign? Or is there any input like 7827392*748347
or lke 98938 + 748347
3) Is there any input which contains number with leading zero,or leading or trailing spaces? like- 0000007688544 or like 8779 * 7368
4) Input numbers always be given on a single line, or not? Is there any input like:
63238372 +
3238

Here is my code, which getting WA.

Code: Select all

Accepted !!
Please help me, and ans on my above confusion.......
And I also submitted another code considering leading zero, which also getting WA. Below is that code:

Code: Select all

Accepted !!
Whats wrong here? :(

Re: 465 - Overflow

Posted: Tue Sep 16, 2014 8:28 pm
by brianfry713
1) Does input contain any negative integer? No
2) The input contains at least one space after first number and after operator sign.
3) Is there any input which contains number with leading zero? Yes
Leading or trailing spaces? Maybe
4) Input numbers always be given on a single line, or not? Single line
scanf("%s%s%s") should work

Try input:
5432 * 1242345

result too big

Re: 465 - Overflow

Posted: Tue Sep 16, 2014 8:56 pm
by Shahidul.CSE
Thank you, sir
Got Accepted!

Mistake was that I calculated value for ans using l<flen instead of l<alen [flen = > length of first number, alen=>length of ans]

What a silly mistake and a stupid I am that I couldn't find it out! :)

Re: 465 - Overflow

Posted: Sun Oct 05, 2014 12:16 pm
by xz816111
help,I've got 45 WAs but I still don't know why...

Code: Select all

finally....

Re: 465 - Overflow

Posted: Sun Oct 05, 2014 1:06 pm
by lighted
Input

Code: Select all

1073741824 + 0
1073741824 * 2
Acc Output

Code: Select all

1073741824 + 0
1073741824 * 2
result too big
Don't forget to remove your code after getting accepted. 8)

Re: 465 - Overflow

Posted: Sun Oct 05, 2014 2:07 pm
by xz816111
thank you so much! :roll:

Re: 465 - Overflow

Posted: Sun Dec 21, 2014 7:14 pm
by gautamzero
what is the problem with me?!!! :x
getting WA in every problem i touch :(
plz help... :(
i have tested every input i got...but not any problem..then WA :x

Code: Select all

erased

Re: 465 - Overflow

Posted: Tue Dec 23, 2014 3:56 am
by brianfry713
Input:

Code: Select all

9999999999999999999999999 * 01
AC output:

Code: Select all

9999999999999999999999999 * 01
first number too big
result too big

Re: 465 - Overflow

Posted: Tue Dec 23, 2014 8:49 am
by gautamzero
another silly mistake...... :oops:
thnx Brian Fry :)

Re: 465 - Overflow

Posted: Tue Jan 20, 2015 10:24 pm
by ehsanulbigboss
Silly Mistake :oops:

Re: 465 - Overflow

Posted: Wed Jan 21, 2015 11:17 pm
by brianfry713
Don't read and write to files.

Re: 465 - Overflow

Posted: Thu Apr 23, 2015 8:17 am
by IhateWA
Help Me plz . Q_Q

I have tried all testcase and these are right.
(except 1111*99999999 or 11+33 .Because I think he input contains at least one space after first number and after operator sign.....)

I dont know why I always get WA...

Code: Select all

/*

*/
//2,147,483,647
#include<iostream>
#include<string.h>
#include <algorithm>
#include<sstream>
#include <iostream>
#include<cstdio>
#define D(x) cout<<#x<<" is "<<x<<endl;
using namespace std;
bool b1,b2,r;

bool Bignum(string t)
{
    reverse(t.begin(),t.end());
    if(t.length()<10) return 0;

    if(t.length()>10)
        for(int i=10;i<t.length();i++)
            if(t[i]!='0') return 1;


    int s[15];
    for(int i=0;i<10;i++)
        s[i]=(int)t[i]-48;

    if(s[9]>2) return 1;
    if(s[9]<2) return 0;
    else
    {
        if(s[8]>1) return 1;
        if(s[8]<1) return 0;
        else
        {
            if(s[7]>4) return 1;
            if(s[7]<4) return 0;
            else
            {
                if(s[6]>7) return 1;
                if(s[6]<7) return 0;
                else
                {
                    if(s[5]>4) return 1;
                    if(s[5]<4) return 0;
                    else
                    {
                        if(s[4]>8) return 1;
                        if(s[4]<8) return 0;
                        else
                        {
                            if(s[3]>3) return 1;
                            if(s[3]<3) return 0;
                            else
                            {
                                if(s[2]>6) return 1;
                                if(s[2]<6) return 0;
                                else
                                {
                                    if(s[1]>4) return 1;
                                    if(s[1]<4) return 0;
                                    else
                                    {
                                        if(s[0]>7) return 1;
                                        else
                                            return 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

bool add(string s1,string s2)
{
    if(b1==1 || b2==1) return 1;
    int s[12];
    memset(s,0,sizeof(s));

    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());


    for(int i=0;i<10;i++)
    {
        if(s1.length()>=i+1 && s2.length()>=i+1) s[i]=(int)s1[i]-48+(int)s2[i]-48;
        else if(s1.length()>=i+1 && s2.length()<i+1) s[i]=(int)s1[i]-48;
        else if(s1.length()<i+1 && s2.length()>=i+1) s[i]=(int)s2[i]-48;
    }

    for(int i=0;i<10;i++)
        if(s[i]>9)
            {
                s[i+1]+=s[i]/10;
                s[i]%=10;
            }

    if(s[10]!=0) return 1;


    if(s[9]>2) return 1;
    if(s[9]<2) return 0;
    else
    {
        if(s[8]>1) return 1;
        if(s[8]<1) return 0;
        else
        {
            if(s[7]>4) return 1;
            if(s[7]<4) return 0;
            else
            {
                if(s[6]>7) return 1;
                if(s[6]<7) return 0;
                else
                {
                    if(s[5]>4) return 1;
                    if(s[5]<4) return 0;
                    else
                    {
                        if(s[4]>8) return 1;
                        if(s[4]<8) return 0;
                        else
                        {
                            if(s[3]>3) return 1;
                            if(s[3]<3) return 0;
                            else
                            {
                                if(s[2]>6) return 1;
                                if(s[2]<6) return 0;
                                else
                                {
                                    if(s[1]>4) return 1;
                                    if(s[1]<4) return 0;
                                    else
                                    {
                                        if(s[0]>7) return 1;
                                        else
                                            return 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
/*
1: 10   | 10 | 1~9
2: 1~9  | 10 | 10
*/

bool mul(string s1,string s2)
{
    int t=0;

    for(int i=0;i<s1.length();i++)
        if(s1[i]=='0') t++;
    if(t==s1.length()) return 0;

    t=0;
    for(int i=0;i<s2.length();i++)
        if(s2[i]=='0') t++;
    if(t==s2.length()) return 0;

    if(b1==1 || b2==1) return 1;

    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());

    int n1[12],n2[12],s[25],i1,i2;
    memset(n1,0,sizeof(n1));
    memset(n2,0,sizeof(n2));
    memset(s,0,sizeof(s));

    for(int i=0;i<10;i++)
        if(i<s1.length())
        {
            n1[i]=(int)s1[i]-48;
            if(n1[i]!=0) i1=i;
        }


    for(int i=0;i<10;i++)
        if(i<s2.length())
        {
            n2[i]=(int)s2[i]-48;
            if(n2[i]!=0) i2=i;
        }

    for(int i=0;i<=i2;i++)
        for(int j=0;j<=i1;j++)
            s[j+i]=n2[i]*n1[j];



    for(int i=0;i<10;i++)
        if(s[i]>9)
        {
            s[i+1]+=s[i]/10;
            s[i]%=10;
        }

    for(int i=10;i<=23;i++)
        if(s[i]!=0) return 1;

    if(s[9]>2) return 1;
    if(s[9]<2) return 0;
    else
    {
        if(s[8]>1) return 1;
        if(s[8]<1) return 0;
        else
        {
            if(s[7]>4) return 1;
            if(s[7]<4) return 0;
            else
            {
                if(s[6]>7) return 1;
                if(s[6]<7) return 0;
                else
                {
                    if(s[5]>4) return 1;
                    if(s[5]<4) return 0;
                    else
                    {
                        if(s[4]>8) return 1;
                        if(s[4]<8) return 0;
                        else
                        {
                            if(s[3]>3) return 1;
                            if(s[3]<3) return 0;
                            else
                            {
                                if(s[2]>6) return 1;
                                if(s[2]<6) return 0;
                                else
                                {
                                    if(s[1]>4) return 1;
                                    if(s[1]<4) return 0;
                                    else
                                    {
                                        if(s[0]>7) return 1;
                                        else return 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

int main()
{
    string line;
    string num1,num2;
    char op;

    while(getline(cin,line))
    {

        cout<<line<<endl;


        istringstream in(line);


        in>>num1;
        in>>op;
        in>>num2;
        b1=0;b2=0;r=0;


        b1=Bignum(num1);
        b2=Bignum(num2);

        if(b1==1) cout<<"first number too big"<<endl;
        if(b2==1) cout<<"second number too big"<<endl;

        if(op=='+') r=add(num1,num2);
        if(op=='*') r=mul(num1,num2);

         if(r==1) cout<<"result too big"<<endl;

    }
    return 0;
}