Page 4 of 7
Re: 424 Got a WA...Pls help!!!!!
Posted: Fri Oct 17, 2008 8:37 pm
by lnr
To theharshest.
Try this.
Input:
Code: Select all
46457567568
3564567756756
2342343
0
Output:
424 Got a WA...Pls help!!!!!
Posted: Tue Dec 30, 2008 11:18 pm
by sazzadcsedu
whats wrong with my code??
i got wA.
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i,add=0;
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;
}
Re: 424 Got a WA...Pls help!!!!!
Posted: Wed Dec 31, 2008 12:16 am
by shiplu_1320
I think you have missed a newline.
Good luck

424
Posted: Sun Nov 01, 2009 9:21 am
by the thing
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;
}
Getting The Msg
Posted: Tue May 25, 2010 9:21 am
by shaon_cse_cu08
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;
}

Re: 424 - Integer Inquiry RE
Posted: Tue May 25, 2010 9:57 am
by sohel
strrev() is not part of ANSI C.
You have to write your own string reverse function.
Re: 424 - Integer Inquiry RE
Posted: Tue May 25, 2010 12:06 pm
by shaon_cse_cu08
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';
}
424-Integer Inquiry. COMPILATION ERROR!!!!
Posted: Fri Jun 18, 2010 11:50 am
by naheed
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
sum=sum.add(i);
}
System.out.println(sum);
}catch(Exception e){
}
}
}
424-Integer Inquiry. COMPILATION ERROR!!!!
Posted: Fri Jun 18, 2010 12:00 pm
by naheed
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
sum=sum.add(i);
}
System.out.println(sum);
}catch(Exception e){
}
}
}
Re: 424 - Integer Inquiry RE
Posted: Wed Jun 23, 2010 5:54 am
by shaon_cse_cu08
Re: 424 - Integer Inquiry RE
Posted: Wed Jun 23, 2010 10:13 am
by sohel
You can generate your own test cases and compare the outputs using gmark's site.
http://uvatoolkit.com/problemssolve.php
Re: 424-Integer Inquiry. COMPILATION ERROR!!!!
Posted: Tue Jun 29, 2010 1:45 am
by programmin
Did you try changing "public class sum" to "public class Main" before submitting?
Re: 424 - Integer Inquiry RE
Posted: Wed Jun 30, 2010 9:06 pm
by Sadasidha08
ur strings length is very small make those 500
Re: 424 - Integer Inquiry RE
Posted: Fri Sep 17, 2010 12:08 pm
by dushyant89
whats wrong here............??????
im getting correct output for all test cases known ever.....
please check it.........
#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;
}
Re: 424 - Integer Inquiry RE
Posted: Fri Sep 17, 2010 12:12 pm
by dushyant89
was getting wrong answer on submitting on uva......
please help friends.........waiting for u.......