|
|
back to boardshould I print YES for the string (**)*) ? the problem says that comments may contain every symbol so, comments may contain *) so, should take the *) as we like so it will match as good as we can, or should we take *) as we meet it in the text? please, give me a test for this source; I still get WA on #1. This is my source: #include<stdio.h> char ch; int sem = 0; char str[16] = "=+-*/0123456789"; int search(char c) { int i; for(i = 0; i < 15; i++) if(c == str[i]) return 0; return 1; } void getChar() { scanf("%c", &ch); } void comment() { while(1) { getChar(); while(ch == '*') { getChar(); if(ch == ')') return; } if(feof(stdin)) { sem = 1; return; } } } void expr() { while(ch != ')') { if(search(ch)) { if(ch == ')') return; else if(ch == '(') { getChar(); if(ch == '*') comment(); else expr(); } else sem = 1; } getChar(); if(feof(stdin)) { sem = 1; return; } } } int main() { do { getChar(); if(feof(stdin)) break; if(ch == '(') { getChar(); if(ch == '*') { comment(); } else expr(); } else if(ch == ')') { sem = 1; break; } } while(!feof(stdin)); if(sem) printf("NO\n"); else printf("YES\n"); return 0; } Edited by author 09.07.2004 18:43 Re: please, give me a test for this source; I still get WA on #1. This is my source: Posted by Nilrem 25 Oct 2005 20:19 Try test: (1+2+3 ) Your program will print NO, but true answer is YES. You must control '\n'... I had same problem... Re: please, give me a test for this source; I still get WA on #1. This is my source: Thank you for the test!! |
|
|