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

Problem with input
Posted by Sid 16 Apr 2005 12:21
It's strange i got wa#1 and i sappose that first test isn't difficult... so perhaps I have problem whith input...

#include <stdio.h>
#include <iostream.h>

int main()
{

    char ar[10000];

    char c,c2;
    bool comment=false;
    int arifm=0,i=0,t;
    //FILE* f;
    //f=fopen("input.txt","r");
    while (scanf("%c",&c)!=EOF)
    {
    ar[i]=c;
    i++;
    }
    for (t=0;t<i;t++)
    {
        if (comment && ar[t]=='*' && t<i-1 && ar[t+1]==')')
        {
            if (!comment)
            {
                    cout<<"NO"<<"\n";
                    return 0;
            }
            comment=false;
            t++;
        }
        else if (!comment)
        {
            if (ar[t]=='(')
            {
                if (t<i-1 && ar[t+1]=='*')
                {
                    comment=true;
                    t++;
                }
                else arifm++;
            }
            else if (ar[t]==')')
            {
                arifm--;
                if (arifm<0)
                {
                    cout<<"NO"<<"\n";
                    return 0;
                }
            }else if (arifm>0)
            {
                if (!((ar[t]>=48 && ar[t]<=57)||ar[t]=='*'||ar[t]=='/'||ar[t]=='+'||ar[t]=='-'||ar[t]=='='))
                {
                    cout<<"NO"<<"\n";
                    return 0;
                }
            }




        }
    }
    if (arifm==0&& !comment)
    {
                    cout<<"YES"<<"\n";
                    return 0;
    }
    else
    {
                    cout<<"NO"<<"\n";
                    return 0;
    }

}