Code: Select all
1
something<BLAH>something</Blah>something
1
something<BLAH>something</Blahlalallalalal>something
1
something<BLAH>something</>something
Moderator: Board moderators
Code: Select all
1
something<BLAH>something</Blah>something
1
something<BLAH>something</Blahlalallalalal>something
1
something<BLAH>something</>something
Code: Select all
Test Case 1
line 1: bad character in tag name.
Test Case 2
line 1: bad character in tag name.
I rewrote the program in order to allow any input size and it was acceptedviniciusweb wrote:I tested my program with all samples posted here and it outputs the correct answer for all of them, but I keep getting "Wrong Answer". Someone pointed out that the input values are big. Does anyone know if a line can have a length of more than 1.000.000 of chars? Also, if anyone have a big sample for this problem (with the correct answers), please post it here. Thanks in advance.
Code: Select all
8
<A> 1st line
<B> 2nd line
<C> 3rd line
</C> 4th line
</B> 5th line
<D> 6th line
7th line
8th line
1
<A>kk<
1
<A>kk</
0
Code: Select all
Test Case 1
line 6: expected </D>
Test Case 2
line 1: bad character in tag name.
Test Case 3
line 1: bad character in tag name.
My output:arif_pasha wrote:Can anyone please give the output for the following test cases:My OutputCode: Select all
8 <A> 1st line <B> 2nd line <C> 3rd line </C> 4th line </B> 5th line <D> 6th line 7th line 8th line 1 <A>kk< 1 <A>kk</ 0
For the first case what should be the correct answer .. line 1 or 6 or 7 or 8 ??Code: Select all
Test Case 1 line 6: expected </D> Test Case 2 line 1: bad character in tag name. Test Case 3 line 1: bad character in tag name.
for the 2nd & 3rd case would it be "expected </A>"
Thanks
Code: Select all
Test Case 1
line 8: expected </D>
Test Case 2
line 1: bad character in tag name.
Test Case 3
line 1: bad character in tag name.
Why the answer to the first test case is expected </D> instead of expected </A>?arif_pasha wrote:Can anyone please give the output for the following test cases:My OutputCode: Select all
8 <A> 1st line <B> 2nd line <C> 3rd line </C> 4th line </B> 5th line <D> 6th line 7th line 8th line 1 <A>kk< 1 <A>kk</ 0
For the first case what should be the correct answer .. line 1 or 6 or 7 or 8 ??Code: Select all
Test Case 1 line 6: expected </D> Test Case 2 line 1: bad character in tag name. Test Case 3 line 1: bad character in tag name.
for the 2nd & 3rd case would it be "expected </A>"
Thanks
Code: Select all
program Project2;
{$H+}
var
a: string;
i,j,l,n,ci: word;
s: array [1..98000] of string[10];
se: longint;
t1: string[15];
fl,err: boolean;
const
uc: set of char = ['A'..'Z'];
begin
readln (n);
ci := 0;
while (n <> 0) do
begin
ci := ci + 1;
writeln ('Test Case ',ci);
se := 1;
err := false;
for i:=1 to n do
begin
readln (a);
if err then continue;
a := a + ' ';
j := 1;
while j<=length(a) do
begin
if err then break;
if a[j]='>' then
begin
writeln ('line ',i,': bad character in tag name.');
err := true;
break
end;
if a[j] = '<' then
begin
fl := false;
t1 := '<';
l := j + 1;
while (l <= length(a)) do
begin
t1 := t1 + a[l];
if a[l] = '>' then
begin
fl := true;
break
end;
if (not (a[l] in uc)) and (a[l] <> '/') then
begin
writeln ('line ',i,': bad character in tag name.');
err := true;
break
end;
if ((length(t1) > 11)and(t1[2]<>'/'))or((length(t1) > 12)and(t1[2]='/')) then
begin
writeln ('line ',i,': too many/few characters in tag name.');
err := true;
break
end;
l := l + 1
end;
j := l+1;
if err then continue;
if not fl then
begin
writeln ('line ',i,': bad character in tag name.');
err := true;
continue;
end;
if (((length(t1) > 12)and(t1[2]<>'/'))or((length(t1) > 13)and(t1[2]='/')))or(((length(t1) < 3)and(t1[2]<>'/'))or((length(t1) < 4)and(t1[2]='/'))) then
begin
writeln ('line ',i,': too many/few characters in tag name.');
err := true;
continue;
end;
if t1[2] = '/' then
begin
se := se - 1;
if se < 1 then
begin
writeln ('line ',i,': no matching begin tag.');
err:= true;
continue;
end
else
begin
delete (t1,1,2);
delete (t1,length(t1),1);
if s[se] <> t1 then
begin
t1 := s[se];
writeln ('line ',i,': expected </',t1,'>');
err := true;
continue;
end
end
end
else
begin
delete (t1,1,1);
delete (t1,length(t1),1);
s[se] := t1;
se := se + 1;
end;
end
else
j := j + 1;
end;
end;
i := n;
if (se>1) and (not err) then
begin
t1 := s[se-1];
writeln ('line ',i,': expected </',t1,'>');
err := true;
end;
if not err then
writeln ('OK');
readln (n);
end;
end.
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 1000
#define N 20
//char stack[M][N];
//int top;
struct ListNode
{
char item[N];
struct ListNode *next;
};
ListNode *top;
void push(char s[N])
{
//strcpy(stack[top],s);
//top++;
ListNode *temp = new ListNode;
strcpy(temp->item,s);
temp->next=top;
top=temp;
}
char *pop()
{
char res[N];
//top--;
//strcpy(res,stack[top]);
//top--;
strcpy(res,top->item);
top = top->next;
return res;
}
int isEmpty()
{
return top==NULL;
}
int main()
{
int cases;
int n,line,idx;
int i,error,tag;
char str[M],store[N],word[N],check[N];
char ch;
top = NULL;
cases=0;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
gets(str);
error = 0;
line = 0;
idx = 0;
strcpy(word,"");
strcpy(check,"");
tag = 0;
top=NULL;
//for(i=0;i<M;i++)
//memset(stack[i],'\0',sizeof(stack[i]));
while(line<n)
{
gets(str);
//tag = 0;
for(i=0;i<strlen(str);i++)
{
ch = str[i];
if( (ch!='>' && ch!='/') && tag)
{
word[idx++]=ch;
}
else if(ch=='<' && !tag)
{
tag=1;
}
else if(ch=='>' && tag==1)
{
if(!idx || idx>10)
error = 2;
else
{
word[idx]='\0';
push(word);
idx=0;
}
tag = 0;
}
else if(ch=='/' && tag==1)
{
tag=2;
}
else if(ch=='>' && tag==2)
{
word[idx]='\0';
if(!isEmpty())
{
strcpy(store,pop());
if(strcmp(store,word)!=0)
error = 3;
}
else
error = 4;
idx=0;
tag = 0;
}
//if(tag)
//error = 1;
if(error)
break;
}
if(tag) error = 1;
if(error)
break;
line++;
}
i = line+1 ;
if(!isEmpty() && !error)
{
error = 3;
strcpy(store,pop());
line--;
}
if(error)
while( i<n)
{
gets(str);
i++;
}
printf("Test Case %d\n",cases+1);
cases++;
if(!error)
printf("OK\n");
else if(error==1)
{
printf("line %d: bad characters in tag name.\n",line+1);
}
else if(error==2)
{
printf("line %d: too many/few characters in tag name.\n",line+1);
}
else if(error==3)
{
printf("line %d: expected </%s>.\n",line+1,store);
}
else if(error==4)
{
printf("line %d: no matching begin tag.\n",line+1);
}
}
return 0;
}