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

gtcoder
New poster
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

Re: 424 - Integer Inquiry RE

Post by gtcoder » Thu Sep 23, 2010 9:00 pm

The memory limits are enough why use so small limits on arrays. Use 1000.

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 424 - Integer Inquiry RE

Post by shaon_cse_cu08 » Tue Nov 16, 2010 7:42 pm

plz help me... I hv used much bigger array.... It's still in no use.... :cry: :(

Code: Select all

#include<stdio.h>
#include<string.h>
void str_rev(char str[]);
int main()
{

	char str[1001][1001],str3[1002];

	int i,j,k,m,x=0,carry=0,max=0;


	for(i=0;i<101;i++)
	{
		gets(str[i]);
	
		if(str[i][0]=='0'&&str[i][1]=='\0')
			break;
	
		if(strlen(str[i])>=max)
			max=strlen(str[i]);
	
	}
	
	j=i;
	for(i=0;i<j;i++)
	{
		str_rev(str[i]);
		for(k=strlen(str[i]);k<max;k++)
		{
			str[i][k]='0';
		}
		str[i][k]='\0';
		str_rev(str[i]);
	}
	

		for(k=max-1,m=0;k>=0,m<max;k--,m++)
		{
			x=0;
			for(i=0;i<j;i++)
			{
		
				x+=(str[i][k]-'0')+carry;
		
				carry=0;
			}
				if(x>9)
				{
					carry=x/10;
					str3[m]=x%10+'0';
				}
				else
					str3[m]=x+'0';	
		}
	
	str3[max]=carry+'0';
		
	if((str3[max]-'0')==0)
		str3[max]='\0';
	else
		str3[max+1]='\0';

	str_rev(str3);
	puts(str3);
		
return 0;
}

void str_rev(char str[])
{
	char a;
	int i,j,n;
	
	n=strlen(str);

	for(i=0,j=n-1;i<n/2&&j>=0;i++,j--)
	{
		a=str[i];
		str[i]=str[j];
		str[j]=a;
	}
	
	str[n]='\0';

}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

424 - Integer Inquiry RE

Post by Eather » Thu Dec 16, 2010 6:38 pm

I dont know why im getting RE?? Plz help me to find out.
I have code in Java using BigInteger.
Here is my Code

Code: Select all

import java.util.*;
import java.math.*;
import javax.swing.*;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);

        BigInteger a,sum;
        
        sum= BigInteger.ZERO;

       while(true){
            a= sc.nextBigInteger();  
            sum= sum.add(a);
            if(a.intValue()==0)break;
       }
        
        System.out.print(sum) ;
    }
}

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 424 - Integer Inquiry RE

Post by live_lie » Fri Jun 17, 2011 8:15 am

what will be the output for

0000
0000
0000
0
plz...

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 424 - Integer Inquiry RE

Post by live_lie » Fri Jun 17, 2011 8:56 am

Got AC

Code: Select all

AC
Last edited by live_lie on Sat Jun 25, 2011 2:00 pm, edited 1 time in total.

live_lie
New poster
Posts: 19
Joined: Mon Nov 29, 2010 11:50 pm

Re: 424 - Integer Inquiry RE

Post by live_lie » Fri Jun 17, 2011 8:56 am

AC

Code: Select all



sabquat
New poster
Posts: 3
Joined: Fri Aug 19, 2011 11:19 am

424 - Integer Inquiry: WA!!!!

Post by sabquat » Fri Aug 19, 2011 11:30 am

plz help me.... :oops:
here is my code-

Code: Select all

#include<stdio.h>

int main()
{
    char inp[101],out[110];
    int i,j,c,tempc;
    for(i=0;i<110;i++)
        out[i]='0';
    while(scanf("%s",inp)==1)
    {
        for(i=0;inp[i]!='\0';i++);
        for(c=0,j=109,i--;i>=0;i--,j--)
        {
            tempc=c;
            c=(c+out[j]+inp[i]-96)/10;
            out[j]=(tempc+out[j]+inp[i]-96)%10+48;
        }
        if(c)
            out[j]=c+out[j];
        if(inp[0]=='0'&&inp[1]=='\0')
        {
            for(i=0;out[i]=='0';i++);
            j=i;
            for(;i<110;i++)
                printf("%c",out[i]);
            printf("\n");
            for(;j<110;j++)
            out[j]='0';
        }
    }
    return 0;
}

asitmahato
New poster
Posts: 11
Joined: Mon Feb 20, 2012 11:04 am

Re: 424, Compile ERROR??

Post by asitmahato » Mon Feb 20, 2012 11:41 am

Just you Include the code given below in your code..

Code: Select all

#include<cstdio>

richi18007
New poster
Posts: 2
Joined: Mon Aug 06, 2012 3:42 pm

Re: 424 - Integer Inquiry RE

Post by richi18007 » Mon Aug 06, 2012 3:48 pm

I am getting WA again and again .. form my side , I think I've covered all the test cases .
The algorithm is also straightforward .... scan - reverse and then add , this too in the reverse fashion and output the results in the reversed fasion as well .Can anyone tell me what am I missing or doing wrongly ?

Code: Select all

code removed after AC 
Last edited by richi18007 on Tue Aug 07, 2012 10:42 am, 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 » Tue Aug 07, 2012 1:29 am

100
1
0
Check input and AC output for thousands of problems on uDebug!

richi18007
New poster
Posts: 2
Joined: Mon Aug 06, 2012 3:42 pm

Re: 424 - Integer Inquiry RE

Post by richi18007 » Tue Aug 07, 2012 10:42 am

brianfry713 wrote:100
1
0
Thanks dude , I got the point . It was my first ever forum post , and it was really helpful . ACed :)

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 10, 2013 11:46 am

code removed
Last edited by mobarak.islam on Wed Jan 23, 2013 7:42 am, 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 10, 2013 11:00 pm

Try input:

Code: Select all

9
9
0
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 15, 2013 8:21 am

code removed
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 » Tue Jan 15, 2013 9:04 pm

Print a newline at the end of the output.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 4 (400-499)”