424 - Integer Inquiry RE

Write here if you have problems with your C source code

Moderator: Board moderators

Re: 424 - Integer Inquiry RE

Postby 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
User avatar
shaon_cse_cu08
New poster
 
Posts: 50
Joined: Tue May 25, 2010 9:10 am

424 - Integer Inquiry RE

Postby 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) ;
    }
}
Eather
New poster
 
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 424 - Integer Inquiry RE

Postby 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

Postby 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

Postby live_lie » Fri Jun 17, 2011 8:56 am

AC
Code: Select all

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

Re: 424 - Integer Inquiry RE

Postby 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.
richi18007
New poster
 
Posts: 2
Joined: Mon Aug 06, 2012 3:42 pm

Re: 424 - Integer Inquiry RE

Postby brianfry713 » Tue Aug 07, 2012 1:29 am

100
1
0
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry RE

Postby 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 :)
richi18007
New poster
 
Posts: 2
Joined: Mon Aug 06, 2012 3:42 pm

Re: 424 - Integer Inquiry RE

Postby 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.
mobarak.islam
New poster
 
Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Postby brianfry713 » Thu Jan 10, 2013 11:00 pm

Try input:
Code: Select all
9
9
0
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry RE

Postby 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.
mobarak.islam
New poster
 
Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Postby brianfry713 » Tue Jan 15, 2013 9:04 pm

Print a newline at the end of the output.
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry RE

Postby 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.
mobarak.islam
New poster
 
Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

Re: 424 - Integer Inquiry RE

Postby 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"
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 424 - Integer Inquiry RE

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

@ brianfry713 , I got accepted. Thanks :)
mobarak.islam
New poster
 
Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

Previous

Return to C

Who is online

Users browsing this forum: No registered users and 1 guest