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

WA1
Posted by Gelioscope 24 Jun 2011 20:10
This is my code:
#include <stdio.h>
#define ulong unsigned long
void main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
    freopen("out.txt","wt",stdout);
#endif
    bool comment=0,arithmetical=0;
    long brakets=0;
    char syms[10001];
    ulong i;
    while(!feof(stdin))
    {
        gets(syms);
        i=0;
        while(syms[i])
        {
            if(comment)
            {
                while(syms[i])
                {
                    if(syms[i]=='*')
                    {
                        ++i;
                        if(syms[i]==')')
                        {
                            ++i;
                            comment=0;
                            break;
                        }
                    }
                    ++i;
                }
            }
            if(arithmetical)
            {
                while(syms[i])
                {
                    if(!((syms[i]>=0x28&&syms[i]<=0x2B)||(syms[i]>=0x30&&syms[i]<=0x39)||syms[i]=='-'||syms[i]=='/'||syms[i]=='\n'||syms[i]=='='))
                    {
                        printf("NO");
                        return;
                    }
                    if(syms[i]=='(')
                    {
                        ++i;
                        if(syms[i]=='*')
                        {
                            ++i;
                            comment=1;
                            break;
                        }
                        ++brakets;
                        continue;
                    }
                    if(syms[i]==')')
                    {
                        ++i;
                        --brakets;
                        if(!brakets)
                        {
                            arithmetical=0;
                            break;
                        }
                    }
                    ++i;
                }
                continue;
            }
            while(syms[i])
            {
                if(syms[i]=='(')
                {
                    ++i;
                    if(syms[i]=='*')
                    {
                        ++i;
                        comment=1;
                        break;
                    }
                    arithmetical=1;
                    ++brakets;
                    break;
                }
                if(syms[i]==')')
                {
                    printf("NO");
                    return;
                }
                ++i;
            }
        }
    }
    if(arithmetical||comment)
    {
        printf("NO");
        return;
    }
    printf("YES");
}
WHY WA1?!
Re: WA1
Posted by Gelioscope 25 Jun 2011 00:55
Give me solution for this task, please, i don't understand why i get WA#1