Page 1 of 9

10340 - All in All

Posted: Thu Aug 01, 2002 10:17 am
by Dominik Michniewski
What's wrong with this code ?? I got WA, but I think, that it could be correct ... maybe any trap I'm missing ?? PLease help

Code: Select all

CUT
I found, that I can edit previously posted messages ;-) so I cut source code ... I'm not sure, that is correct way to prevent someone to copy-paste method to solve problems ... :-( but I think, that only when source code has errors should be post here...

Posted: Thu Aug 01, 2002 11:42 am
by Adrian Kuegel
Change this:
If (len1>len2) ...
and after
if (*p == 0) return 0;
there should be p++;
because you can't use the same letter twice.

Posted: Thu Aug 01, 2002 12:46 pm
by Dominik Michniewski
Thanks, thanks and again thanks Adrian ....
I forgot about incrementing p after while loop :oops:
I got Accepted now :-))

Dominik
BTW. In description I can't see where it written that the same strings are for "Yes" answer ... but OK :-)) Thanks again :-)

10340

Posted: Sun Aug 04, 2002 11:53 am
by Rivaldo
I think my program is no problem. But it got runtime error.

[pascal]
const
name1 = '';
name2 = '';
maxn = 10000;
var
s,t : array[1 .. maxn] of char;
ls,lt : integer;

procedure init;
var w : char;
begin
ls := 0; lt := 0;
fillchar(s, sizeof(s), 0);
fillchar(t, sizeof(t), 0);
read(w);
while w <> ' ' do begin
inc(ls);
s[ls] := w;
read(w);
end;
while w = ' ' do read(w);
while (w <> ' ') and not eoln do begin
inc(lt);
t[lt] := w;
read(w);
end;
if w <> ' ' then begin inc(lt); t[lt] := w; end;
readln;
end;

procedure main;
var i,j : integer;
begin
j := 1;
for i := 1 to ls do begin
while (j <= lt) and (s <> t[j]) do inc(j);
if s <> t[j] then begin
writeln('No'); exit;
end
else if i = ls then
if i = ls then writeln('Yes')
else
else inc(j);
end;
end;

begin
assign(input, name1);
reset(input);
assign(output, name2);
rewrite(output);

while not eof do begin
init;
main;
end;
close(input);
close(output);
end.
[/pascal]

Posted: Sun Aug 04, 2002 12:37 pm
by xenon
Why open another tread for this problem?

Runtime Errors give information about the kind of error that was encountered, so look at that information to solve the problem. In your case you probably got 'Illegal Memory Reference', or something like that, which means that the program tries to access memory that doesn't belong to it.
Since you only allocated 10000 bytes of memory for the two inputbuffers, they are the most probable offenders. Try to increase their sizes.

Posted: Sun Aug 04, 2002 3:34 pm
by Rivaldo
Thanks! I got AC now. :D

10340

Posted: Wed Aug 21, 2002 1:13 pm
by htl
Why does this code get RE? Is it possible that the length of
the string over 10000?
[c]
#include<stdio.h>
#include<string.h>
void main(void)
{
int **table,x,lens,lent,y,p;
char *s,*t;
s=(char *)malloc(sizeof(char)*10001);
t=(char *)malloc(sizeof(char)*10001);
table=(int **)malloc(sizeof(int *)*2);
for(x=0;x<2;x++)
table[x]=(int *)malloc(sizeof(int)*10001);
while(scanf("%s %s",s,t)!=EOF)
{
lens=strlen(s);
lent=strlen(t);
for(x=0;x<=lent;x++)
table[0][x]=0;
for(x=0,p=1;x<lens;x++,p=1-p)
{
table[p][0]=0;
for(y=0;y<lent;y++)
if(s[x]==t[y])
table[p][y+1]=table[1-p][y]+1;
else if(table[p][y]>=table[1-p][y+1])
table[p][y+1]=table[p][y];
else
table[p][y+1]=table[1-p][y+1];
}
if(table[1-p][lent]==lens)
printf("Yes\n");
else
printf("No\n");
}
free(table);
free(s);
free(t);
}
[/c]

Posted: Wed Aug 21, 2002 2:24 pm
by Adrian Kuegel
Yes, it is possible, why do you ask? It is obvious that this would cause a runtime error, so if you get RE in a problem like this you should first try to allocate more memory before asking in the forum, and please use existing threads (there is one about this problem). In this case the string is not longer than 500000 and perhaps shorter, but if you want to be sure use 500000 as upper limit.

10340, why wa?

Posted: Fri Aug 30, 2002 2:37 pm
by HKcow
Could any one help me to check why it is getting wa?

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

void main() {
char *a, *b;
a = new char [200000];
b = new char [200000];

int i, j;
while (scanf("%s %s", a, b)== 2) {
j=0;
for (i=0; (a!='\0') && (b[j]!='\0'); i++)
for (; (b[j]!='\0') && (a!=b[j]); j++);
if (b[j]!='\0')
printf("Yes\n");
else
printf("No\n");
}
delete [] a;
delete [] b;
}[/cpp]

Posted: Fri Aug 30, 2002 3:46 pm
by Dominik Michniewski
try with
aaa aaa

answer is "Yes" - you have "No" (I think)
I made same mistake ...

Posted: Fri Aug 30, 2002 8:35 pm
by HKcow
Oh thx, but I got this right.
But
aa bab
i will get correct~
^_^, thx
HKcow

Posted: Sun Oct 27, 2002 6:07 pm
by Eric
Surely, your array is too small :D

Posted: Sat Nov 23, 2002 5:47 am
by jamesng
Hi Homeway,

I too got WA for my program. May I know what you discovered about your program that's wrong? Thanx alot.

10340 - about to give up

Posted: Fri Dec 27, 2002 1:42 am
by zsepi
if someone could explain me why I get WA on this, it would be appreciated... I tested it with everything I could think of and it worked fine....
here is the code
[cpp]
#include <iostream.h>
#include <string.h>

#define MX 1000000

main() {
char o[MX],e[MX]; /* original, encoded */
int i,j,ol,el;

cin >> o >> e;
while(!cin.eof()) {
i=0;
j=0;
ol=strlen(o);
el=strlen(e);
if(ol<=el) {
while(i<ol) {
while(j<el && o!=e[j]) j++;
if(j==el) break;
i++;
}
if(o==0) cout << "Yes" << endl;
else cout << "No" << endl;
}
else cout << "No" << endl;
cin >> o >> e;
}
}
[/cpp]
thanks!

Posted: Mon Dec 30, 2002 11:36 pm
by tat tvam asi
helo
... try the following
input "file" :
A A~
where ~ stands for EOF .
bye