#include #include int l,i; char sir[105]; // variabila/numar 1 // paranteza [ 2, ] 3 // BX/BP 4, SI/DI 5 // +/- 6 inline bool lit(char &c) { if(c>='a'&&c<='z') return 1; return 0; } inline bool cif(char &c) { if(c>='0'&&c<='9') return 1; return 0; } inline int get_ch(int poz) { if(sir[poz]=='B'||sir[poz]=='b') if(sir[poz+1]=='X'||sir[poz+1]=='x'||sir[poz+1]=='P'||sir[poz+1]=='p') { ++i; return 4; } if(sir[poz]=='S'||sir[poz]=='s'||sir[poz]=='D'||sir[poz]=='d') if(sir[poz+1]=='I'||sir[poz+1]=='i') { ++i; return 5; } if(lit(sir[poz])&&!lit(sir[poz+1]))return 1; if(cif(sir[poz])&& !cif(sir[poz+1]))return 1; if(sir[poz]=='[')return 2; if(sir[poz]==']')return 3; if(sir[poz]=='+'||sir[poz]=='-')return 6; return -1; } bool eval() { int last=0,now,ap4=0,ap5=0,par=0,var=0; for(i=0;i1)return 0; if(last==1||last==4||last==5)return 0; }else if(now==2)// paranteza [ 2 { ++par; }else if(now==3)// paranteza ] 3 { --par; if(par<0)return 0; if(last==6)return 0; //if(last==2)return 0; ? }else if(now==6)// +/- 6 { if(last==0||last==2)return 0; }else if(now==4)// BX/BP 4 { ++ap4; if(ap4>1)return 0; if(last==1)return 0; }else if(now==5)// SI/DI 5 { ++ap5; if(ap5>1)return 0; if(last==1)return 0; } last=now; } if(last==6||par)return 0; return 1; } int main() { //freopen("date.in","r",stdin); int ok; while(gets(sir)) { l=strlen(sir); ok=eval(); if(ok) printf("OK\n"); else printf("ERROR\n"); } return 0; }