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

any tricks on Test 8? I keep getting WA on it
Posted by Sa Lang Hae 30 Oct 2004 14:31
subj
Re: any tricks on Test 8? I keep getting WA on it
Posted by Nilrem 23 Oct 2005 17:58
You solved this problem...
Help me PLEASE!!!!!!!!!!
I got WA8 too.. +(
Show the code.
Posted by +FAMAS+ 24 Oct 2005 01:18
Re: Show the code.
Posted by Nilrem 25 Oct 2005 20:08
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char *text;
bool dpp=true;
void comments();/* (* Comments *) */
void alu(); /* (1+2+3(5+6+7))  */
void mloop()
{
    while(*text&&dpp)
    {

        if(text[0]=='(')
        {
            if(text[1]=='*')
            {
                text+=2;
                comments();
                continue;
            }
            else
            {
                text+=1;
                alu();
                continue;
            }

        }
        text++;

    }
}
void alu()
{
   while(1)
   {
        if(text[0]==')')
        {
            text+=1;
            return;
        }

        else
        {
            if(text[0]=='(')
            {
                if(text[1]=='*')
                {
                    text+=2;
                    comments();
                    continue;
                }
                else
                {
                    text+=1;
                    alu();
                    continue;
                }
            }
            else
            {

                if((text[0]==' ')||(!isdigit(text[0])&&*text!='+'&&*text!='-'&&*text!='*'&&*text!='/'&&*text!='='&&*text!='\n'&&*text!='\r') )
                {

                    dpp=false;
                    return;
                }

            }
        }
        text++;

   }
}
void comments()
{
   while(*text)
   {
    if(text[0]=='*')
    {
        if(text[1]==')')
        {
            text+=2;
            break;
        }
    }
    text++;

   }
   if(!*text)dpp=false;

}
int balans()/* Test for '(' and ')' */
{
    int k=0,n=0;
    while(*text)
    {
        if(*text=='(')
        {
            text++;
            if(*text=='*')
            {
                text++;
                comments();
                if(dpp==false)return 1;
                continue;
            }
            else {k++;continue;}

        }
        else
        {
            if(*text==')')
                n++;
        }
        text++;
    }
    if (k==n) return 0;
    else return 1;
}
int main()
{
    char *txt2,*txt3;
    text=(char*)malloc(10001);
    txt3=(char*)malloc(501);
    memset(txt3,0,sizeof(txt3));
    memset(text,0,sizeof(text));
    while(!feof(stdin))
    {
        fgets(txt3,500,stdin);
        strcat(text,txt3);
        memset(txt3,0,sizeof(txt3));

    }
    txt2=text;

    if(balans()==0)
    {
        text=txt2;

        mloop();
        if(dpp) printf("YES");
        else printf("NO");
    }
    else printf("NO");



}

It's my code...
It's not clear... But it work on all test which i found on this  discuss...What can be on #8 ? +(
Test #8 contains a ')' immediatly after a '('.
Posted by Szabolcs Ivan 22 Nov 2005 20:09
Re: Show the code.
Posted by xj.ammo 27 Nov 2005 02:45
You should change this:
void comments()
{
while(*text)
{
if(text[0]=='*')
{
if(text[1]==')')
{
text+=2;
return;
}
}
text++;

}
dpp=false;

}
Re: Show the code.
Posted by Alexander (201 - P TNU) 3 Jan 2008 00:43
Are you crazy?
Re: Show the code.
Posted by Alexander (201 - P TNU) 3 Jan 2008 00:44
Nilrem, Are you crazy?