Page 2 of 7

424 WA

Posted: Sun Apr 24, 2005 1:45 am
by dootzky
i've checked the forum, and found several posts about p424.
but none of them seems to help my program. :cry:

could someone tell me what am i doing wrong?
i simply read one line, go from end to begining, and if my last digit is >9, i take step like digit = digit - 10, and simply transfer that one level (number?) up on the next digit. that's all. it SHOULD work, works for all of my test inputs, even for those posted on this forum, but i still get WA. :evil:

here's my code, i hope someone can help me.

Code: Select all

#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

void main() {

	int i,c,cmax,br[11000];
	char a[11000];
	cmax=0;
	for (i=0;i<101;i++) br[i]=0;

	while (gets(a)) {

		if ((strlen(a)==1) && (a[0]=='0')) break; // end sequence
		c=0;

		for (i=strlen(a)-1;i>-1;i--) {
			if (( ((int)a[i]-48) + br[c]) > 9) {
				br[c] += ((int)a[i]-48) - 10; 
				br[c+1]++; 
				cmax=c+1;
				while (br[cmax]>9) {br[cmax] -= 10; br[++cmax]++;}
			}
			 else br[c] += ((int)a[i]-48);
			c++;
		}

		
	} // end of while

	c=1;
	for (i=100;i>-1;i--) if ((br[i]!=0)&&(c==1)) {cmax=i+1; c=0;}

	for (i=cmax-1;i>-1;i--) cout << br[i];
	cout << endl;

}

Posted: Sun Apr 24, 2005 2:17 am
by Sanny
Results can be more than 101 digits. :wink:

Regards
Sanny

Posted: Mon Apr 25, 2005 11:51 pm
by dootzky
you know what... nevermind! :D

forget that code. i was really hoping to do it correctly my way, with reading and processing one line at the time, but since i couldn't, i used another approach:

i read all the lines, and add ALL the numbers in one big integer array.
then i simply say somethin' like:

array[c+1] = array[c] / 10;
array[c++] %= 10;

and that worked!! i got ACC.
i hate when i can't get the problem from the first time, but hey - that's life! :evil:

thx for your help, thou. :D 8)

Problem 424... Please help, I really don't know what to do n

Posted: Sun Jun 26, 2005 8:48 pm
by Piotr
Problem 424... Please help, I really don't know what to do now :/// I still got WA

program p424;

{$APPTYPE CONSOLE}

uses
SysUtils;
var
t: array[1..100,1..100] of byte;
t2: array[1..200] of byte;

i,j,poz: integer;
s:ansistring;
b: boolean;

begin


for i:=1 to 100 do
for j:=1 to 100 do
t[i,j]:=0;

for i:=1 to 200 do t2:=0;

poz:=1;
s:='';


b:=false;
while not(s='0') do
begin
readln(s);
if (s='0')and(b=false) then break;


b:=true;
i:=101-length(s);
for j:=1 to length(s) do
begin
t[poz,i]:=ord(s[j])-48;
inc(i);
end;
inc(poz);
end;

poz:=200;

for i:=100 downto 1 do
begin
for j:=1 to 100 do
t2[poz]:=t2[poz]+t[j,i];
dec(poz);
end;




for i:=199 downto 1 do
t2:=t2+(t2[i+1] div 10);


for i:=2 to 200 do
t2:=t2 mod 10;



j:=1;

while t2[j]=0 do inc(j);



s:='';
for i:=j to 200 do
s:=s+chr(t2+48);

writeln(s);



end.

424-pls help

Posted: Thu Jun 30, 2005 3:46 pm
by 59557RC
can any1 pls help me abt 424-integer inquiry my code below :
#include<stdio.h>
#include<string.h>
int main(void)
{

char p[101][101],q[101][101],res[101];
int i,j,t,max,len[100],sum=0,c=0,k=0;

for(i=0;;i++) {scanf("%s",&p);if(strcmp(p,"0\0")==0) break; }
max=i;
for(i=0;i<max;i++) len=strlen(p);

for(i=0;i<max;i++){
k=0;
for(j=0;j<100-len;j++){
q[j]='0';}
for(;j<100;j++){
q[j]=p[k];k++;
}

}

/*for(i=0;i<max;i++) {
for(j=0;j<100;j++){
printf("%c",q[j]);}printf("\n");}
*/

j=0;





for(k=99;k>=0;k--){
sum=0;
for(i=0;i<max;i++) {

sum+=q[k]-'0'; }
sum+=c;
c=sum/10;
t=sum%10;

res[j]=t+'0'; j++;

}

for(i=j-1;i>=0;i--) if(res[i]!='0') break;

for(;i>=0;i--) printf("%c",res[i]);

return 0;
}

Posted: Tue Oct 04, 2005 9:53 pm
by n00i3
i dont understand the language sorry but i think that the idea is to input as a string and then add the two strings character by character :p

424! Why WA?!

Posted: Fri Feb 24, 2006 9:26 am
by scidong

Code: Select all

#include<iostream.h>
#include<string.h>
#include<memory.h>

char s[10001];

void main(){
	int i,j,c,cl;
	char a[10001];
	while(cin >> a){
		c=strlen(a);
		if(c == 1 && a[0]=='0') break;
		else{
			for(i=0; i<c; i++){
				s[i]+=a[c-i-1]-'0';
				for(j=0; j<i; j++){
					if(s[j]>=10){
						s[j+1]++;
						s[j]-=10;
					}
				}
			}
		}
	}
	for(i = 0; i<10001; i++){
		if(s[i]!=0) cl=i;
	}
	for(i=cl; i>=0; i--) cout << int(s[i]);
	cout << endl;
}
Oh...
Plz give me a hint(or why am I WA).
plz...

Posted: Fri Feb 24, 2006 9:29 am
by scidong
I did. but still WA!

Posted: Sat Jul 22, 2006 2:13 am
by daveon
Hi,

Why do you break on c==1?

424. Compile Error. Help me~

Posted: Tue Aug 15, 2006 9:15 am
by mosaick2
My code is a little long. but, Actually, I have already written my BigInteger class. So, I just want to reuse my class.

My program is well-working at VC and G++.
However, online-judge give me C.E(compile error).
Who know about this problem?
Give me your idea, plz...

Code: Select all

 deleted 
----
Thankx, bro : )

Re: 424. Compile Error. Help me~

Posted: Tue Aug 15, 2006 9:32 am
by surya ss
mosaick2 wrote:My code is a little long. but, Actually, I have already written my BigInteger class. So, I just want to reuse my class.
here is the error :
04831250_24.c: In method `class BigInt BigInt::operator +(const BigInt
&)':
04831250_24.c:47: implicit declaration of function `int max(...)'

in the jugde compiler, it don't have function named max()

you must declare it yourself

Posted: Tue Aug 15, 2006 9:38 am
by mf
in the jugde compiler, it don't have function named max()

you must declare it yourself
Actually, it does have it, you just have to #include <algorithm> to use it.

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

Posted: Fri Oct 27, 2006 4:55 am
by ahah2002
I got WA for 424, but I don't know what is wrong of my code, pls help...

#include <iostream>
#include <string>
using namespace std;
int main(){
string str[110];
string str2[110];
string result;
char* ch;
char p;
int i,j,k;
int maxl;
int x10,x1;
int n;

i=0;
do{

cin>>str;
if (str[0]=='0' && (str.length()==1)){
break;
}
i++;
}while (1);

maxl=str[0].length();
for (j=0;j<i;j++){
if (str[j].length()>maxl){
maxl=str[j].length();
}
for (k=0;k<str[j].length();k++){
str2[j]+=str[j][str[j].length()-1-k];
}
}

n=0;
x10=0;
x1=0;
for (j=0;j<maxl;j++){
for (k=0;k<i;k++){
if (j<str2[k].length()){
p=str2[k][j];
ch=&p;
n+=atoi(ch);
}
}
n+=x10;
x1=n%10;
x10=n/10;
result[j]='0'+x1;
if (j==maxl-1){
if (n>=10){
result[++j]='0'+x10;
}
}

n=0;
}


for(i=j;i>=0;i--){
cout<<result;
}


return 0;
}

Posted: Sun Oct 29, 2006 9:21 am
by Wei-Ming Chen
Your output existed a space before the answer.

If the input is

Code: Select all

5
5
5
0
The output is

Code: Select all

15
But your output is

Code: Select all

 15

Posted: Mon Oct 30, 2006 1:25 pm
by emotional blind
input:

Code: Select all

99
99
99
99
99
99
99
99
99
99
99
99
99
0
Your output:

Code: Select all

 <87
:o