342 - HTML Syntax Checking

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

CrazyTerabyte
New poster
Posts: 25
Joined: Fri Jul 16, 2004 3:19 am
Location: Brazil
Contact:

Post by CrazyTerabyte » Wed Apr 19, 2006 4:38 pm

What is the output for this case:

Code: Select all

1
something<BLAH>something</Blah>something
1
something<BLAH>something</Blahlalallalalal>something
1
something<BLAH>something</>something
The problem is not clear if that should print "expected </BLAH>" or "badcharacter" or "too many/few characters"

Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post by Erik » Sun Oct 15, 2006 8:05 pm

Hi,

what should be the output for

Code: Select all

2
hi<BL
U> go </BLU> too
1
<A
0
Cu, Erik :)

Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post by Erik » Sun Oct 15, 2006 9:51 pm

Hi,

I got it accepted.
The correct answers are

Code: Select all

Test Case 1
line 1: bad character in tag name.
Test Case 2
line 1: bad character in tag name.
Cu, Erik :)

viniciusweb
New poster
Posts: 24
Joined: Sun Nov 12, 2006 3:38 pm

Post by viniciusweb » Fri Feb 09, 2007 12:48 am

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.

viniciusweb
New poster
Posts: 24
Joined: Sun Nov 12, 2006 3:38 pm

Post by viniciusweb » Fri Feb 09, 2007 8:07 pm

viniciusweb 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.
I rewrote the program in order to allow any input size and it was accepted :) .

arif_pasha
New poster
Posts: 42
Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh
Contact:

Post by arif_pasha » Wed Feb 28, 2007 7:22 pm

Can anyone please give the output for the following test cases:

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
My Output

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 first case what should be the correct answer .. line 1 or 6 or 7 or 8 ??
for the 2nd & 3rd case would it be "expected </A>"

Thanks

viniciusweb
New poster
Posts: 24
Joined: Sun Nov 12, 2006 3:38 pm

Post by viniciusweb » Thu Mar 01, 2007 12:13 am

arif_pasha wrote:Can anyone please give the output for the following test cases:

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
My Output

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 first case what should be the correct answer .. line 1 or 6 or 7 or 8 ??
for the 2nd & 3rd case would it be "expected </A>"

Thanks
My output:

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.
In the first case, the </D> is mandatory, but it can be in any line after the <D>. Since the output ended in the 8th line and there was no </D>, that's the line where the error occurs.

In the 2nd and 3rd case, there is a start tag character "<", but the next char is a newline, so it's a bad character error.

arif_pasha
New poster
Posts: 42
Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh
Contact:

Post by arif_pasha » Thu Mar 01, 2007 12:49 am

Thanks viniciusweb

I got it accepted after a lot of tries.. :D
I got WA for the first test ...

Arif

silva1107
New poster
Posts: 2
Joined: Thu Mar 15, 2007 6:09 pm

Post by silva1107 » Fri Mar 16, 2007 7:00 am

arif_pasha wrote:Can anyone please give the output for the following test cases:

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
My Output

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 first case what should be the correct answer .. line 1 or 6 or 7 or 8 ??
for the 2nd & 3rd case would it be "expected </A>"

Thanks
Why the answer to the first test case is expected </D> instead of expected </A>?
According to the spec expected </A> is the first error....

User avatar
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio » Sun Mar 18, 2007 5:51 am

Becase </D> is expected before </A>.

silva1107
New poster
Posts: 2
Joined: Thu Mar 15, 2007 6:09 pm

Post by silva1107 » Mon Apr 02, 2007 4:14 pm

rio wrote:Becase </D> is expected before </A>.
Oh, I see.. Thank you very much.

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post by andysoft » Sat Jul 14, 2007 10:25 am

Hi people!
I am still getting W.A. in this problem.
But I think this is because my stack is not big enough to place all the tags.

Please, tell me, what size is your (with AC) stack for opening tags?

I use array [1..80000] of string[12] and I don't know is it enough (80000 opening tags)?

Thanx in advance
Now I lay me down to sleep...
my profile

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post by andysoft » Sat Jul 14, 2007 10:51 am

It's everything OK with my solution, but judge is saying WA, because (I am almost sure) stack isn't big enough for all tags. But when I make it bigger, I get Memory Limit (without it, I would get AC).
And it's bad that there's nothing about tag number limit in task description. :(
Now I lay me down to sleep...
my profile

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post by andysoft » Sat Jul 14, 2007 10:55 am

WHAT THE HELL?
When stack is array [1..99999] of string[10], judge says my prog takes only 1400 of memory, but when size is [1..100000] (yeah, only +1), judge says I take 36192 of memory, which is 26 times bigger!!
Can someone please explain me....

btw, my code:

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.
Now I lay me down to sleep...
my profile

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan » Mon Aug 27, 2007 8:11 am

Whats wrong with ma code ..... when submit it with Cpp it says invalid memory reference and with C it says compiler error .... i found no error in my compiler 'TC' :( .....

What's the size of 'a' line ??
is it ok with gets??
does the input accept only UPPERCASES tag ???
if it does not accept mixed cases tag then whats the error ??

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;
}



Thanks in advanced
Time that gone is gone forever ...

Post Reply

Return to “Volume 3 (300-399)”