|
|
back to boardWhy "Crash (ACCESS_VIOLATION)" ? I have program: #include <stdio.h> #include <ctype.h>
char buf[11000];
int pos,len; int f;
void fail() { f = 0; // printf("pos = %d\n%s\n",pos,buf + pos); }
void Load() { pos = 0; len = fread(buf,1,11000,stdin); f = 1; buf[len] = 0; }
void parseComment() { while(buf[pos]!='*' || buf[pos+1]!=')') { if(pos == len-2) { fail(); return; } pos++; } pos += 2; }
void parseMath() { int N = 0; while(1) { if(pos == len - 1) { if(buf[pos] != ')') fail(); pos++; return; } if(buf[pos]=='(' && buf[pos+1]=='*') { pos+=2; parseComment(); if(f==0) return; continue; } if(buf[pos]=='(') { N++; } if(buf[pos]==')') { if(N>0) N--; else { pos++; return; } } if(buf[pos]!=10 && buf[pos]!=13 && buf[pos]!='(' &&buf[pos]!=')' &&buf[pos]!='*' && buf[pos]!='-' && buf[pos]!='+' && buf[pos]!='/' && buf[pos]!='=' && !isdigit(buf[pos])) { fail(); return; } pos++; } }
void Solve() { while(pos < len) { if(buf[pos]=='(' && buf[pos+1]=='*') { pos+=2; parseComment(); if(f==0) return; continue; } if(buf[pos]=='(') { pos++; parseMath(); if(f==0) return; continue; } if(buf[pos]==')') { fail(); return; } pos++; } }
void Save() { if(f) printf("YES\n"); else printf("NO\n"); }
int main() { Load(); Solve(); Save(); return 0; }
|
|
|