424 - Integer Inquiry
Moderator: Board moderators
Re: 424 - Integer Inquiry RE
The memory limits are enough why use so small limits on arrays. Use 1000.
-
- New poster
- Posts: 50
- Joined: Tue May 25, 2010 9:10 am
- Contact:
Re: 424 - Integer Inquiry RE
plz help me... I hv used much bigger array.... It's still in no use....
![:cry:](./images/smilies/icon_cry.gif)
![:(](./images/smilies/icon_frown.gif)
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](./images/smilies/icon_mad.gif)
![:x](./images/smilies/icon_mad.gif)
424 - Integer Inquiry RE
I dont know why im getting RE?? Plz help me to find out.
I have code in Java using BigInteger.
Here is my Code
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) ;
}
}
Re: 424 - Integer Inquiry RE
what will be the output for
0000
0000
0000
0
plz...
0000
0000
0000
0
plz...
Re: 424 - Integer Inquiry RE
Got AC
Code: Select all
AC
Last edited by live_lie on Sat Jun 25, 2011 2:00 pm, edited 1 time in total.
Re: 424 - Integer Inquiry RE
AC
Code: Select all
424 - Integer Inquiry: WA!!!!
plz help me....
here is my code-
![:oops:](./images/smilies/icon_redface.gif)
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;
}
-
- New poster
- Posts: 11
- Joined: Mon Feb 20, 2012 11:04 am
Re: 424, Compile ERROR??
Just you Include the code given below in your code..
Code: Select all
#include<cstdio>
-
- New poster
- Posts: 2
- Joined: Mon Aug 06, 2012 3:42 pm
Re: 424 - Integer Inquiry RE
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 ?
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
-
- New poster
- Posts: 2
- Joined: Mon Aug 06, 2012 3:42 pm
Re: 424 - Integer Inquiry RE
Thanks dude , I got the point . It was my first ever forum post , and it was really helpful . ACedbrianfry713 wrote:100
1
0
![:)](./images/smilies/icon_smile.gif)
-
- New poster
- Posts: 38
- Joined: Wed Dec 05, 2012 11:29 pm
Re: 424 - Integer Inquiry RE
code removed
Last edited by mobarak.islam on Wed Jan 23, 2013 7:42 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 424 - Integer Inquiry RE
Try input:
Code: Select all
9
9
0
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 38
- Joined: Wed Dec 05, 2012 11:29 pm
Re: 424 - Integer Inquiry RE
code removed
Last edited by mobarak.islam on Tue Jan 22, 2013 3:59 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 424 - Integer Inquiry RE
Print a newline at the end of the output.
Check input and AC output for thousands of problems on uDebug!