## 424 - Integer Inquiry

Moderator: Board moderators

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 424 Got a WA...Pls help!!!!!

To theharshest.
Try this.
Input:

Code: Select all

``````46457567568
3564567756756
2342343
0
``````
Output:

Code: Select all

``````3611027666667
``````

Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Contact:

### 424 Got a WA...Pls help!!!!!

whats wrong with my code??
i got wA.

Code: Select all

``````          #include<stdio.h>
#include<string.h>

int   main()

{

int j=0,carry,sum,max;
char num[102];
int  res[105];

for(i=0;i<105;i++)
{
res[i]=0;
}

max=0;

while(scanf("%s",num)==1)

{
if(num[0]==48 && num[1]=='\0')

break;

sum=0;
carry=0;
j=0;
for(i=strlen(num)-1;i>=0;i--)

{
sum=res[j]+(num[i]-48)+carry;

if(sum>9)
{

res[j]=(sum%10) ;
carry=sum/10;

}
else
{
res[j]=sum ;
carry=0 ;
}

j++;

}
while(carry>0)
{
res[j]=(carry+res[j]);

carry=res[j]/10;
res[j]=res[j]%10;

j++;

}

if(max<j-1)
max=j-1;

}

for(i=max;i>=0;i--)
{
printf("%d",res[i]);
}

return 0;
}

``````
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359

shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

### Re: 424 Got a WA...Pls help!!!!!

I think you have missed a newline.
Good luck
A learner......

the thing
New poster
Posts: 1
Joined: Sun Nov 01, 2009 9:07 am

### 424

my code of 424 is below.i ma gettin WA.help me PLz

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
//freopen("vli.txt","r",stdin);
int m,l,i,carry,ans[105],allow;
char str[101],temp[10];
for(i=0;i<105;i++)
{
ans=0;
}
while((scanf("%s",str))==1)
{
if(!(strcmp(str,"0"))) break;

m=strlen(str);
l=m-1;
carry=0;
for(i=104;i>=0;i--)
{
ans=ans+carry;
if(l>=0)
{
temp[0]=str[l];
temp[1]='\0';
ans=ans+atoi(temp);
}
carry=0;
if(ans>9)
{
carry=ans/10;
ans=ans%10;
}
l--;
}
}
allow=0;
for(i=0;i<105;i++)
{
if(ans==0)
{
if(allow) printf("%d",ans[i]);
}
else
{
printf("%d",ans[i]);
if(!allow) allow=1;
}

}
return 0;
}

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

### Getting The Msg

Hey Can any one tel me why i m getting this msg :
(Compilation Error)
code.cpp: In function 'int main()':
code.cpp:23: error: 'strrev' was not declared in this scope
code.cpp:58: error: 'strrev' was not declared in this scope

My code in visual c++ is as follows:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{

char str[101][101],str3[102];

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

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

for(k=max-1,m=0;k>=0,m<max;k--,m++)
{
x=0;
for(i=0;i<j;i++)
{

x+=(str[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';

puts(strrev(str3));

return 0;
}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around .....

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: 424 - Integer Inquiry RE

strrev() is not part of ANSI C.
You have to write your own string reverse function.

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

### Re: 424 - Integer Inquiry RE

Now This is WA....
What could possibly be wrong....plz Help

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

char str[101][101],str3[102];

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

for(i=0;i<101;)
{
gets(str);
if(atol(str)<0)
continue;
else
{
if(strcmp(str,"0")==0)
break;
if(strlen(str)>=max)
max=strlen(str);
i++;
}
}
j=i;
for(i=0;i<j;i++)
{
str_rev(str);
for(k=strlen(str);k<max;k++)
{
str[k]='0';
}
str[k]='\0';
str_rev(str);
}

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

printf("\n");

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 .....

naheed
New poster
Posts: 8
Joined: Sun Oct 25, 2009 7:20 pm

### 424-Integer Inquiry. COMPILATION ERROR!!!!

Why CE in this Java program?????Runs farely well in Netbeans,JCreator..No error.PLZ HELP..

Code: Select all

``````import java.util.*;
import java.math.*;

public class sum {
public static void main(String[] args) {
try{
BigInteger sum;
BigInteger zero=new BigInteger("0");
sum=zero;
Scanner in=new Scanner(System.in);

while(true){

BigInteger i;
i=in.nextBigInteger();
if(i.equals(zero))
break;
else
}
System.out.println(sum);
}catch(Exception e){

}
}
}
``````

naheed
New poster
Posts: 8
Joined: Sun Oct 25, 2009 7:20 pm

### 424-Integer Inquiry. COMPILATION ERROR!!!!

Why CE in my first java submission??? SMONE PLZ help!

Code: Select all

``````import java.util.*;
import java.math.*;

public class sum {
public static void main(String[] args)throws IOException {
try{
BigInteger sum;
BigInteger zero=new BigInteger("0");
sum=zero;
Scanner in=new Scanner(System.in);

while(true){

BigInteger i;
i=in.nextBigInteger();
if(i.equals(zero))
break;
else
}
System.out.println(sum);
}catch(Exception e){

}
}
}
``````

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

### Re: 424 - Integer Inquiry RE

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

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: 424 - Integer Inquiry RE

You can generate your own test cases and compare the outputs using gmark's site.
http://uvatoolkit.com/problemssolve.php

programmin
New poster
Posts: 2
Joined: Mon Jun 28, 2010 11:51 pm

### Re: 424-Integer Inquiry. COMPILATION ERROR!!!!

Did you try changing "public class sum" to "public class Main" before submitting?

New poster
Posts: 3
Joined: Mon Apr 05, 2010 8:09 pm

### Re: 424 - Integer Inquiry RE

ur strings length is very small make those 500

dushyant89
New poster
Posts: 2
Joined: Fri Sep 17, 2010 12:03 pm

### Re: 424 - Integer Inquiry RE

whats wrong here............??????
im getting correct output for all test cases known ever.....

#include<iostream>
using namespace std;
int main()
{
char ch[110][110];
int i=0,rem=0,j,k,max=0,disp,a;
char str[200];
while(cin>>ch)
{
if(strlen(ch)==1 && ch[0]=='0')
break;
if(strlen(ch)>max)
max=strlen(ch);
i++;
}
for(k=max-1;k>=0;k--)
{ a=rem;
for( j=0;j<i;j++)
{disp=max-strlen(ch[j]);
if((k-disp)>=0)
a=a+ch[j][k-disp]-48;
}
rem=a/10;
str[k]=a%10 +48;
}
if(rem>0)
cout<<rem;
cout<<str;
return 0;

}

dushyant89
New poster
Posts: 2
Joined: Fri Sep 17, 2010 12:03 pm

### Re: 424 - Integer Inquiry RE

was getting wrong answer on submitting on uva......