424 - Integer Inquiry

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

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Post by mobarak.islam » Thu Jan 17, 2013 11:27 am

Code removed after getting accepted
Last edited by mobarak.islam on Tue Jan 22, 2013 3:59 pm, edited 1 time in total.

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

Re: 424 - Integer Inquiry RE

Post by brianfry713 » Thu Jan 17, 2013 9:48 pm

For input

Code: Select all

100
100
0
the output should be:"200\n", you're printing "2\n0\n0\n"
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Post by mobarak.islam » Tue Jan 22, 2013 3:58 pm

@ brianfry713 , I got accepted. Thanks :)

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 424, Compile ERROR??

Post by Shihab » Mon Dec 30, 2013 9:11 pm

CE ! why?

Code: Select all

#include<stdio.h>
int main()
{
    int i=1,j,k,d,l,l1,l2,sum,carry,max;
    char text[101][101];

    while(gets(text[i]),text[i][0]!='0')
    {
        sum=carry=0;
        if(i>=2)
        {
            l1=strlen(text[i-1])-1;
            l2=strlen(text[i])-1;

            if(l2>l1)
            {
                //l1=strlen(text[i-1])-1;
                //l2=strlen(text[i])-1;

                j=max=l2;
                //j=l1;
                d=l2-l1;
                //printf("-%s\n",text[i-1]);
                for(k=1; k<=d; k++)
                {
                    l1=strlen(text[i-1])-1;
                    for(l=l1; l>=0; l--)
                    {
                        //printf("%c %c\n",text[i-1][l+1],text[i-1][l]);
                        text[i-1][l+1]=text[i-1][l];
                    }
                }
                for(k=0; k<d; k++)
                    text[i-1][k]='0';
                //printf("%d\n",d);
                //printf("-%s\n",text[i-1]);
            }
            else if(l1>l2)
            {
                //l1=strlen(text[i-1])-1;
                //l2=strlen(text[i])-1;

                j=max=l1;
                //j=l2;
                d=l1-l2;
                for(k=1; k<=d; k++)
                {
                    l2=strlen(text[i])-1;

                    for(l=l2; l>=0; l--)
                        text[i][l+1]=text[i][l];
                }
                for(k=0; k<d; k++)
                    text[i][k]='0';
                //printf("+%s\n",text[i]);
            }
            else
            {
                l1=strlen(text[i-1]);
                l2=strlen(text[i]);

                max=l1;
                j=l1-1;

            }
            while(j>=0)
            {
                //printf("%c %c\n",text[i-1][j],text[i][j]);
                sum=(text[i-1][j]-'0')+(text[i][j]-'0')+carry;//Adding two numbers
                if(sum>9)
                {
                    text[i][j]=(sum%10)+'0';
                    carry=1;
                }
                else
                {
                    text[i][j]=sum+'0';
                    carry=0;
                }
                //printf("%c",text[i][j]);
                j--;
            }
            if(carry==1)
            {
                for(j=max; j>=0; j--)
                    text[i][j+1]=text[i][j];
                text[i][0]='1';

            }
            //printf("*%s\n",text[i]);
        }
        i++;
    }
    printf("%s\n",text[i-1]);
    return 0;
}

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

Re: 424, Compile ERROR??

Post by brianfry713 » Thu Jan 16, 2014 12:36 am

You can click My Submissions to see the reason for your CE.
#include <string.h>
Check input and AC output for thousands of problems on uDebug!

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

424 - Integer Inquiry. Why RTE???

Post by me33 » Thu Mar 06, 2014 12:02 am

Please help me...

getting RTE..

my code.

Code: Select all

Removed After AC...
Last edited by me33 on Sun Mar 09, 2014 7:42 pm, edited 1 time in total.

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

Re: 424 - Integer Inquiry. Why RTE???

Post by brianfry713 » Thu Mar 06, 2014 11:18 pm

Don't use a package.
http://uva.onlinejudge.org/index.php?op ... &Itemid=30
Post in the appropriate forum, volume IV instead of General.
Check input and AC output for thousands of problems on uDebug!

me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

Re: 424 - Integer Inquiry. Why RTE???

Post by me33 » Sun Mar 09, 2014 7:42 pm

Thanks brianfry713...

Got AC :D :) :D

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

UVA problem no. 424 WA

Post by richatibrewal » Sat Jun 28, 2014 8:05 pm

Code removed
Last edited by richatibrewal on Sun Jul 20, 2014 6:10 pm, edited 1 time in total.

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

Re: UVA problem no. 424 WA

Post by brianfry713 » Mon Jul 07, 2014 11:18 pm

Input:

Code: Select all

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
0
AC output:

Code: Select all

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999900
Check input and AC output for thousands of problems on uDebug!

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

Re: UVA problem no. 424 WA

Post by richatibrewal » Thu Jul 17, 2014 9:14 am

I am getting the required output

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

Re: UVA problem no. 424 WA

Post by lighted » Thu Jul 17, 2014 11:01 am

You must increase parameters

Code: Select all

char a[100],b[1];
int i=0,k,sum=0,j[100][100]={0},m,f[100]={0},n=0,l,o,p=0,d,max=INT_MIN;
It must be

Code: Select all

char a[101],b[2];
int i=0,k,sum=0,j[101][101]={0},m,f[101]={0},n=0,l,o,p=0,d,max=INT_MIN;
For all problems make limit of arrays bigger than problems says. :wink:
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

Re: UVA problem no. 424 WA

Post by richatibrewal » Thu Jul 17, 2014 5:08 pm

Thank u so much. My code is now accepted :)
:D

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

Re: UVA problem no. 424 WA

Post by lighted » Fri Jul 18, 2014 8:17 am

It will be good if you 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

Nahian.Sunny
New poster
Posts: 6
Joined: Tue Oct 21, 2014 12:51 pm

Re: 424 - Integer Inquiry

Post by Nahian.Sunny » Tue Oct 21, 2014 12:53 pm

Why i am getting WA each time? i have tried all test cases available...but still it's WA!!! can anyone help plz???????????????

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    string s;
    char a[110];
    int i,j,c,b,n=0;
    for(i=0;i<110;i++)
        a[i]='0';
    a[i]=NULL;
    while(1)
    {
        getline(cin,s);
        if(s=="0")
            break;
        if(n<s.size()) n=s.size();
        c=0;
        for(i=s.size()-1,j=0;i>=0;i--,j++)
        {
            b=(s[i]-'0')+(a[j]-'0')+c;
            if(b>9)
            {
                c=b/10;
                a[j]=(b%10)+'0';
            }
            else
            {
                c=0;
                a[j]=b+'0';
            }
        }
        if(c>0)
        {
            while(c!=0)
            {
                b=(a[j]-'0')+c;
                a[j]=(b%10)+'0';
                c=(b+c)/10;
                j++;
            }
        }
    }
    if(a[n]!='0') cout << a[n];
    for(i=n-1;i>=0;i--)
        cout << a[i];
    cout << endl;
    return 0;
}
Last edited by brianfry713 on Tue Oct 21, 2014 7:35 pm, edited 1 time in total.
Reason: Added code blocks

Post Reply

Return to “Volume 4 (400-499)”