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<<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<<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