URAL 1027 d++ Again

Source: Internet
Author: User

Flood problem, string matching ...

But I have been wa ..... Woo Hoo

Take precedence over comments, and then look in the parentheses (judging if something is right in parentheses),,, anything else ....

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <cstdio>

Class Application
{
string file;
Public
Application ()
{
Char RC;
while ((Rc=cin.get ())!=eof) File.push_back (RC);
}
int run ()
{
BOOL Comment=false;
int counter=0;
int last=~ (1&LT;&LT;31);
BOOL Answer=true;
for (int i=0;i<file.size (); i++)
{
if (comment)
{
if (file[i]== ' * ') last=i;
else if (file[i]== ') ' &&last+1==i) Comment=false;
}
else if (counter)
{
if (file[i]== ' * ' &&last+1==i)
{
counter--;
last=~ (1&LT;&LT;31);
Comment=true;
}
else if (file[i]== ') ')
{
counter--;
}
else if (file[i]== ' (')
{
counter++;
last=i;
}
Else
{
BOOL Valid=false;
for (char* j= "=+-*/0123456789) (\ n"; *j;j++)
if (file[i]==*j) valid=true;
if (!valid) Answer=false;
}
}
Else
{
if (file[i]== ' (')
{
counter++;
last=i;
}
else if (file[i]== ') ')
{
Answer=false;
}
}
}
if (comment| | Counter) Answer=false;
cout<< (char*) (answer? ") YES ":" NO ") <<endl;
return 0;
}
};

int main ()
{
Application app;
return App.run ();
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

URAL 1027 d++ Again

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.