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

Sa Lang Hae any tricks on Test 8? I keep getting WA on it [7] // Problem 1027. D++ Again 30 Oct 2004 14:31
subj
You solved this problem...
Help me PLEASE!!!!!!!!!!
I got WA8 too.. +(
+FAMAS+ Show the code. [5] // Problem 1027. D++ Again 24 Oct 2005 01:18
Nilrem Re: Show the code. [4] // Problem 1027. D++ Again 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 ? +(
Szabolcs Ivan Test #8 contains a ')' immediatly after a '('. // Problem 1027. D++ Again 22 Nov 2005 20:09
xj.ammo Re: Show the code. // Problem 1027. D++ Again 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;

}
Alexander (201 - P TNU) Re: Show the code. // Problem 1027. D++ Again 3 Jan 2008 00:43
Are you crazy?
Alexander (201 - P TNU) Re: Show the code. // Problem 1027. D++ Again 3 Jan 2008 00:44
Nilrem, Are you crazy?