Page 1 of 7

Posted: Mon Sep 23, 2002 1:11 pm
by Picard
char type has a -128..127 value range. you only deal with carry at the end, so it may happen that e[x] has value range overflow earlier (like in the example: 15*9=135 > 127)

424, Compile ERROR??

Posted: Tue Nov 19, 2002 1:20 pm
by CCC
[cpp]#include <iostream>
using namespace std;
struct Number
{
char Carry, charShow;
};
Number add(char, char, char);

void main()
{
int NumInputed = 0, i, lengthSum = 0, lengthInput = 0;
char curr, *Input, *Sum, PreCarry = '0';
bool invalid;

Number PreNumber;


Sum = new char;
Input = new char;

while((curr=getchar()) !=10)
{
Sum[lengthSum] = curr;
lengthSum++;
}


while (lengthSum !=0 || Sum[0] != '0')
{
invalid = false;
lengthInput = 0;
while((curr=getchar()) !=10)
{
Input[lengthInput] = curr;
lengthInput++;
}

if(lengthInput == 1 && Input[0] == '0')
break;

for(i=0; i<lengthInput;i++)
if (Input < '0' || Input > '9')
invalid = true;

if (invalid)
continue;

if (lengthInput <= lengthSum)
{
for (i=lengthInput-1; i>=0; i--)
Input[i+(lengthSum-lengthInput)] = Input;
for(i=0; i<lengthSum - lengthInput ; i++)
Input = '0';

lengthInput = lengthSum;
}
else
{
for (i=lengthSum-1; i>=0; i--)
Sum[i+(lengthInput-lengthSum)] = Sum;
for(i=0; i<lengthInput - lengthSum ; i++)
Sum = '0';

lengthSum = lengthInput;
}

for(i=lengthSum-1; i>=0; i--)
{
PreNumber = add(Sum,Input,PreCarry);
Sum = PreNumber.charShow ;
PreCarry = PreNumber.Carry;
}
if (PreCarry == '1')
{
for (i = lengthSum; i>0 ; i--)
Sum = Sum[i-1];
Sum[0] = PreCarry;
lengthSum++;
}
NumInputed++;
}

for (i=0; i<lengthSum;i++)
cout << Sum[i] ;
cout << "\n";

}

Number add(char a, char b, char c)
{
Number ReturnNumber;
int CharShow;
CharShow = (int)a+(int)b+(int)c-3*(int)'0';
if(CharShow >= 10)
{
CharShow -= 10;
ReturnNumber.Carry = '1';
}
else
ReturnNumber.Carry = '0';
ReturnNumber.charShow = (char)(CharShow+(int)'0');
return ReturnNumber;
};[/cpp]

i can Ccompile it and run in Visual C++ sucessfully, it says it is compile error when i submit it to online judge......can any one help me?

Posted: Thu Dec 12, 2002 12:22 pm
by ec3_limz
Hi,

Sometimes, even if a program is compilable in VC++, it may not be able to compile in the online judge because the online judge is using GCC, a different C++ compiler. Try compiling your program with DJGPP or Bloodshed Dev-C++.

Also, will you mind posting the replies from the judge's compiler?

Posted: Tue Dec 17, 2002 10:25 am
by CCC
Thx a lot, i will try using these compiler

424(W.A)

Posted: Sat Mar 15, 2003 10:04 am
by lendlice
I get W.A
Anyone can help me
[cpp]
#include<stdio.h>
#include<string.h>
main()
{
char num[100000],out[100000],ch;
int i=0,n=0,carry=0,ans[100000],k=0,tr=0,j=0;
while(1)
{
n=strlen(out);
for(i=0;i<n;i++)
{
ans=0;
out='\0';
}
while(scanf("%s",num)==1)
{
n=strlen(num);
if(num[0]=='0'&&n==1)
break;
i=0;
for(n=n-1;n>=0;n--)
{
ans=num[n]-'0'+carry+ans;
out=ans+'0';
i++;
}
}

n=strlen(out);
for(j=0;j<n;j++)
{
ch=out[j]+carry;
out[j]=(out[j]-'0'+carry)%10+'0';
carry=(ch-'0')/10;
}
if(carry!=0)
{
printf("%d",carry);
tr++;
}
n=strlen(out);
for(n=n-1;n>=0;n--)
{
if(tr!=0||out[n]!='0')
{
printf("%c",out[n]);
tr++;
}
}
printf("\n");
carry=0;
}
}[/cpp]

Posted: Sun Mar 23, 2003 6:58 am
by Nick
I use one string (array char) to store the num each time.... add it to an array of integer.......then calculate the carry at the last time
U dont need big arrays....

Code: Select all

char num[102];
int res[105];
that should be enough

Hope it'll help you guys,
Nick

424 Why WA

Posted: Sat May 10, 2003 1:38 pm
by Rene
Please help me!
why WA?
[cpp]
#include <iostream.h>
#include <stdio.h>

int max = 104;
int k;
int sum[105];

void main()
{
char c;
int i,j,k1,x;
int sum1[105];
k = max;
while (1)
{
for (i = 0;(c = getchar()) != '\n';i++)
sum1 = c - 48;
if (!sum1[0]) break;
k1 = i - 1;
j = max;
x = 0;
for (i = k1;i >= 0;i--)
{
x = sum[j] + sum1 + x;
sum[j] = x % 10;
x /= 10;
j--;
}
if (k > j)
k = j + 1;
while (x > 0)
{
k--;
sum[k] = x % 10;
x /= 10;
}
}
for (i = k;i <= max;i++)
cout << sum;
cout << endl;
}

[/cpp]

Posted: Sat May 17, 2003 5:35 am
by Red Scorpion
Hi!

your code still wrong, try this:
93
93
93
93
0

Posted: Sun May 18, 2003 10:08 am
by Rene
i have checked my code and got AC
thanx :D

424 WA ...

Posted: Sat Jun 07, 2003 5:00 pm
by Calvin
hi!

watch my code please. I got a WA for this, but i try so much input.. can you give me some input which create a WA ??

[c]#include <stdio.h>
#include <string.h>

int main()
{
int somme[110]={0};
char tmp[100],i,j,max=0;

scanf("%s",tmp);

while (strlen(tmp)>1 || tmp[0]!=48)
{
j=0;

for (i=strlen(tmp)-1;i>=0;i--)
{
somme[j]+=(tmp-48);
j++;
}

scanf("%s",tmp);
}

for (i=0;i<110;i++)
{
if (somme>9) somme[i+1]+=somme/10;
somme=somme%10;
}

max=109;

while (!somme[max] && max>0) max--;

while (max>=0) printf("%d",somme[max--]);

printf("\n");

return 0;
}[/c]

Thanks

Posted: Tue Mar 09, 2004 4:36 pm
by A1
I think You have solve this.
If yet you don't, then make your 'tmp' array size little big :-?
and then remove your code from here :evil:
it is almost AC code!

calvin

Posted: Tue Mar 09, 2004 7:54 pm
by osan
just change tmp[100]
hope u will get Ac if u use tmp[1000]
& pls remove ur code from forum

Problem 424 - Dont know whats's Wrong ?

Posted: Fri Jun 18, 2004 6:38 pm
by raihan_aiub
I tried every possible input for this problem. It works perfectly well but the online judge gives a " Wrong Answer ". Please help !!

Posted: Fri Jun 18, 2004 8:47 pm
by jagadish
if u need any help on a problem please go through the previous posts.. in most cases u can figure out what you are missing and more importantly be specific ..how can anyone make out why you are getting WA unless you give your algo or code?
anyway for this problem try changing the size of array to large value like 11000..

Posted: Sun Aug 29, 2004 11:28 pm
by wolf
Hi! The only thing you have to do is to change the tmp[100] for tmp[101]. Remember that strings are being kept with the end of the string character (just zero) :-D. I had the same problem before.

P.S. Remove the code form forum, please