465 - Overflow

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Rika71
New poster
Posts: 11
Joined: Sat Apr 26, 2014 9:42 pm

Re: 465 - Overflow

Post by Rika71 » Sat Aug 23, 2014 8:38 pm

cant get ac. please help.

Code: Select all

got ac

Last edited by Rika71 on Tue Aug 26, 2014 1:51 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 465 - Overflow

Post by lighted » Mon Aug 25, 2014 8:23 pm

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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Rika71
New poster
Posts: 11
Joined: Sat Apr 26, 2014 9:42 pm

Re: 465 - Overflow

Post by Rika71 » Tue Aug 26, 2014 1:53 pm

thanks for replying, lighted.

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 465 - Overflow

Post by Shahidul.CSE » Tue Sep 16, 2014 5:12 pm

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? :(
Last edited by Shahidul.CSE on Tue Sep 16, 2014 9:02 pm, edited 2 times in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 465 - Overflow

Post by brianfry713 » Tue Sep 16, 2014 8:28 pm

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
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 465 - Overflow

Post by Shahidul.CSE » Tue Sep 16, 2014 8:56 pm

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! :)
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

xz816111
New poster
Posts: 5
Joined: Sun Oct 05, 2014 12:12 pm

Re: 465 - Overflow

Post by xz816111 » Sun Oct 05, 2014 12:16 pm

help,I've got 45 WAs but I still don't know why...

Code: Select all

finally....
Last edited by xz816111 on Sun Oct 05, 2014 2:06 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 465 - Overflow

Post by lighted » Sun Oct 05, 2014 1:06 pm

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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

xz816111
New poster
Posts: 5
Joined: Sun Oct 05, 2014 12:12 pm

Re: 465 - Overflow

Post by xz816111 » Sun Oct 05, 2014 2:07 pm

thank you so much! :roll:

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh

Re: 465 - Overflow

Post by gautamzero » Sun Dec 21, 2014 7:14 pm

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
Last edited by gautamzero on Tue Dec 23, 2014 8:47 am, edited 1 time in total.
None but a fool is always right..
so don't be upset when u r wrong..

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 465 - Overflow

Post by brianfry713 » Tue Dec 23, 2014 3:56 am

Input:

Code: Select all

9999999999999999999999999 * 01
AC output:

Code: Select all

9999999999999999999999999 * 01
first number too big
result too big
Check input and AC output for thousands of problems on uDebug!

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh

Re: 465 - Overflow

Post by gautamzero » Tue Dec 23, 2014 8:49 am

another silly mistake...... :oops:
thnx Brian Fry :)
None but a fool is always right..
so don't be upset when u r wrong..

ehsanulbigboss
New poster
Posts: 32
Joined: Tue Jul 22, 2014 1:17 am

Re: 465 - Overflow

Post by ehsanulbigboss » Tue Jan 20, 2015 10:24 pm

Silly Mistake :oops:
Last edited by ehsanulbigboss on Thu Feb 05, 2015 9:54 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 465 - Overflow

Post by brianfry713 » Wed Jan 21, 2015 11:17 pm

Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!

IhateWA
New poster
Posts: 2
Joined: Thu Apr 23, 2015 8:08 am

Re: 465 - Overflow

Post by IhateWA » Thu Apr 23, 2015 8:17 am

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;
}

Post Reply

Return to “Volume 4 (400-499)”