|
|
back to boardHelp. I got WA & i have no idea why. // D++ Again #include <iostream.h> #include <ctype.h> short ok=1; int exp=0, com=0; void comment() { char c, cpop=' '; while (cin.get(c) && !(c==')' && cpop=='*')) cpop=c; if (c==')' && cpop=='*') com--; } void expression() { char c, cpop; while (cin.get(c) && c!=')' && ok) { if (!isdigit(c) && c!='=' && c!='+' && c!='-' && c!='*' && c!='/' && c!='(' && c!=')' && c!='\n' && c!='\r') ok = 0; if (c=='*' && ok) { if (cpop=='(') { com++; comment(); } } else if (cpop=='(' && ok) { exp++; expression(); } } if (c==')') exp--; } void text() { char c, cpop=' '; while (ok && cin.get(c)) { if (c=='*') { if (cpop=='(') { com++; comment(); } } else if (cpop=='(') { exp++; expression(); } cpop=c; } if (exp || com) ok=0; } void check() { text(); if (ok) cout << "YES"; else cout << "NO"; } int main() { check(); return 0; } |
|
|