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

What's wrong with my program? I got WA
Posted by Band of Brothers 1 Jan 2003 11:53
/*
 * URAL 1027
 * Wrong Answer
 */

#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

void getout() {cout<<"NO"<<endl; exit(0);}

int main()
{
    char t[30000];
    int incomment=0,arth=0,len,i;
    while (!cin.eof())
    {
        t[0]=0;
        cin.getline(t,30000,'\n');
        len=strlen(t);
        for (i=0;i<len;i++)
        {
            if (!incomment&&t[i]=='('&&t[i+1]=='*') incomment=1,i++;
            else if (incomment)
            {
                if (t[i]=='*'&&t[i+1]==')') incomment=0,i++;
            }
            else
            {
                if (t[i]=='(') arth++;
                else if (t[i]==')') arth--;
                else if
(arth!=0&&!(t[i]=='='||t[i]=='+'||t[i]=='-'||t[i]=='*'||t[i]=='/'||(t[i]>='0'&&t[i]<='9')))
                    getout();
            }
            if (arth<0) getout;
        }
    }
    if (arth!=0||incomment) getout();
    cout<<"YES"<<endl;
    return 0;
}