ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1027. D++ Again

should I print YES for the string (**)*) ?
Posted by thwomass 8 Jul 2004 18:32
the problem says that comments may contain every symbol so, comments may contain *)
so, should take the *) as we like so it will match as good as we can, or should we take *) as we meet it in the text?
Correct answer is NO
please, give me a test for this source; I still get WA on #1. This is my source:
Posted by thwomass 9 Jul 2004 18:41
#include<stdio.h>

char ch;
int sem = 0;
char str[16] = "=+-*/0123456789";

int search(char c)
{
    int i;
    for(i = 0; i < 15; i++)
        if(c == str[i]) return 0;
    return 1;
}

void getChar()
{
    scanf("%c", &ch);
}

void comment()
{
    while(1)
    {
        getChar();
        while(ch == '*')
        {
            getChar();
            if(ch == ')') return;
        }
        if(feof(stdin)) { sem = 1; return; }
    }
}

void expr()
{
    while(ch != ')')
    {
        if(search(ch))
        {
            if(ch == ')') return;
            else if(ch == '(')
            {
                getChar();
                if(ch == '*') comment();
                else expr();
            }
            else sem = 1;
        }
        getChar();
        if(feof(stdin)) { sem = 1; return; }
    }
}

int main()
{
    do
    {
        getChar();
        if(feof(stdin)) break;
        if(ch == '(')
        {
            getChar();
            if(ch == '*')
            {
                comment();
            }
            else
                expr();

        }
        else if(ch == ')')
        {
            sem = 1;
            break;
        }
    }
    while(!feof(stdin));

    if(sem) printf("NO\n");
    else printf("YES\n");
    return 0;
}

Edited by author 09.07.2004 18:43
Re: please, give me a test for this source; I still get WA on #1. This is my source:
Posted by Nilrem 25 Oct 2005 20:19
Try test:
(1+2+3
)

Your program will print NO, but true answer is YES.
You must control '\n'...
I had same problem...
Re: please, give me a test for this source; I still get WA on #1. This is my source:
Posted by maksim32 24 Sep 2016 03:55
Thank you for the test!!