391 - Mark-up

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

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

391 - Mark-up .... help !

Post by Dominik Michniewski »

Could anyone give me any special cases for this problem ?
I use finite state machine to solve this question, but stil got WA ....

Is any other trick than I have to print "34" where I found "\s1.234" ??
And what should I print where I found "\S1.123" ??

L33T Magus
New poster
Posts: 1
Joined: Tue Aug 13, 2002 9:48 pm

Post by L33T Magus »

Did you remember that if the input text ends with a '\' it needs to be printed?

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Yes, I remember it .....
But if input looks like

A\
B\

should I print

A\
B\

or
A
B\
?????????????????????????

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 »

Code: Select all

Is any other trick than I have to print "34" where I found "\s1.234" ?? 
And what should I print where I found "\S1.123" ??
output should be nothing for \s1.234 and and "S1.123"
some tricky case i know is :

Code: Select all

input:
\s3.4a\sb\s.5c\s100.d\s12e
\**\\***\\*\*\*

output:
abcde
*\**\*
also don't forget that you don't have to reset the control/mark-up flag on each line (this is where i failed before i got AC)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I don't know what's wrong with this code ....
I got the same result as you, arc16, but still WA
could anyone help me ?

Dominik
------------------------------

Code: Select all

I cut off the code, because it was a solution after some modifications ;-)
Last edited by Dominik Michniewski on Mon Sep 23, 2002 10:31 am, edited 1 time in total.

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 »

Dominik Michniewski wrote:I don't know what's wrong with this code ....
I got the same result as you, arc16, but still WA
could anyone help me ?
haven't take a deep look at your program, but my guess is that
your program cannot process either a sequencing '\' and '*' characters correctly. Check out the following test case:

Code: Select all

input:
\**\\***\\*\*\*
\*
\\
\*
\\ \a\b\c\d\e\f\g\\h\\\*

your output:
*\**\*

\\

\ \a\c\d\e\f\g\h\

correct output:
*\**\*

\\

\ acdefg\h\
see? in the last line, the mark-up control in your program is curreny off, while it should be on. Try to do some more testing with something like \**\\\\\\\\\\\\\\\\\***********\*\*\\*\***\\****\\\*\*\*\*\a\c

good luck :D

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Thanks all for helping me :-)
I got Acceoted now :-)

arc16: thank you very much for very usefull test cases and hints :-))

Dominik

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

I cant understan how the output for \\ be \\. From the problem description it is clear that \\ will be replaced by \.
from problem:
the mark-up \\ can be used to print a single \.
will anybody please help. I am getting wrong answer all the time. :oops: :oops: :oops:

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion »

Consider This sample:

:lol:

Code: Select all

Sample Input
LSKD AODP.
\\ akdf \\
\* asifj \\ \\\
\\\\
\\ askf asf\afa\
\*  \\ \bisjaf

Output:
LSKD AODP.
\ akdf \
 asifj \\ \\\
\\\\
\\ askf asf\afa\
  \ isjaf
Did You see the difference?
when the input is "\\" You should print the "\" when the toggle processing of mark-ups on;
otherwise you should print exactly as they appear in the input.

Note:
At the start, processing of mark-ups should be on.
RS. :lol:

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

Thanks for your reply. My program matches with all the input and output of yours. Will anybody kindly see my program and tell me where i am wrong. Here is my code:

Code: Select all

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

main()
{
	char a[10000];
	int flag1,flag2,flag3,flag4,i,j,l1;	
	while(1)
	{
		if(gets(a)==NULL) break;
		l1=strlen(a);
		flag1=flag2=flag3=0;
		for(i=0;i<l1;i++)
		{
			if(a[i]=='\\')
			{
				if(a[i+1]=='b'&&flag4!=0) {i++;flag1=1;}
				else if(a[i+1]=='s'&&flag4!=0)
				{
					flag2=1;
					for(j=i+2;;j++)
						if(!((a[j]>='0' && a[j]<='9')||a[j]=='.')) break; ;
					i=j-1;
				}
				else if(a[i+1]=='*')
				{
					i++;
					if(flag4==0) flag4=1;
					else flag4=0;

				}
				else if(a[i+1]=='\\'&&flag4!=0)
				{
					i++;
					printf("\\");
				}
				else if (flag4==0) printf("%c",a[i]);
			}
			else printf("%c",a[i]);
		}
		printf("\n");
	}
	return 0;
}
Thanks in advance.


anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »


if there be space charecter after the mark up off,
will i print it or not..
i found the problem harder then i guessed before..
-- if the mark up command is off then all the charecters get printed or not..
if yes then the code of yahoo has no mistakes i think...
--if no please reply why?
--anupam
"Everything should be made simple, but not always simpler"

N|N0
New poster
Posts: 36
Joined: Tue Jan 25, 2005 10:33 pm
Location: Ljubljana, Slovenija
Contact:

Post by N|N0 »

I've no idea why this does not work :-?

Code: Select all

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define ON 1
#define OFF 0

int main(void) {
  char vrsta[100000];
  char *p;
  int process = ON, pika, prva = 1;
  while (!feof(stdin)) {
    gets(vrsta);
    p = vrsta;
    if (!prva) putchar('\n'); else prva = 0;
    while (*p != '\0') {
      if (*p == '\\') {
        if (*(p+1) == 'b' && process) {
          p+=2;
        } else if (*(p+1) == 'i' && process) {
          p+=2;
        } else if (*(p+1) == '*') {
          process = (process==ON)?OFF:ON;
          p+=2;
        } else if (*(p+1) == 's' && process) {
          p+=2;
          pika = 0;
          while (isdigit(*p) || (*p == '.' && !pika)) {
            if (*p == '.') pika++;
            p++;
          }
        } else {
          if (!process) {
            putchar(*p);
            p++;
          } else {
            if (*(p+1) != '\0') {
              p++;
              putchar(*p);
              p++;
            } else {
             p++;
             putchar('\\');
            } 
          }
        }
      } else {
        putchar(*p);
        p++;
      }
    }
  }
  return(0);
}
Any suggestion?

Navid666
New poster
Posts: 7
Joined: Tue Jul 26, 2005 8:06 pm
Contact:

391 - Mark-up

Post by Navid666 »

remove after accept!
Last edited by Navid666 on Wed Jul 12, 2006 9:21 pm, edited 1 time in total.
=;GOOD LUCK=;
NAvidOP

Navid666
New poster
Posts: 7
Joined: Tue Jul 26, 2005 8:06 pm
Contact:

Post by Navid666 »

is any body there???....please help me this is very easy problem and i dont know why i got WA?????????????????? :(:((:(
=;GOOD LUCK=;
NAvidOP

hyperion
New poster
Posts: 8
Joined: Sun Aug 07, 2005 2:21 pm

May this helps you !

Post by hyperion »

Hi Navid,

Test this input to your program, it should generate the output
below which my Accepted Code generated.
Hope you figure out your problem with this test cases. :D

Input :

\s3.4a\sb\s.5c\s100.d\s12e
\*\b no translation should occur *\\ \b*\s3.*\*
/i/b/s\bb\ii\ss
\**\\***\\*\*\*
\*
\\
\*
\\ \n\o\ \p\r\ob\l\e\m\*s\*
\* close literal text by end-of-file\

Desired Output :

abcde
\b no translation should occur *\\ \b*\s3.*
/i/b/sbis
*\**\*

\\

\ no problems
close literal text by end-of-file\

Post Reply

Return to “Volume 3 (300-399)”