|
|
вернуться в форумany tricks on Test 8? I keep getting WA on it subj Re: any tricks on Test 8? I keep getting WA on it Послано Nilrem 23 окт 2005 17:58 You solved this problem... Help me PLEASE!!!!!!!!!! I got WA8 too.. +( Re: Show the code. Послано Nilrem 25 окт 2005 20:08 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> char *text; bool dpp=true; void comments();/* (* Comments *) */ void alu(); /* (1+2+3(5+6+7)) */ void mloop() { while(*text&&dpp) {
if(text[0]=='(') { if(text[1]=='*') { text+=2; comments(); continue; } else { text+=1; alu(); continue; }
} text++; } } void alu() { while(1) { if(text[0]==')') { text+=1; return; }
else { if(text[0]=='(') { if(text[1]=='*') { text+=2; comments(); continue; } else { text+=1; alu(); continue; } } else {
if((text[0]==' ')||(!isdigit(text[0])&&*text!='+'&&*text!='-'&&*text!='*'&&*text!='/'&&*text!='='&&*text!='\n'&&*text!='\r') ) {
dpp=false; return; } } } text++; } } void comments() { while(*text) { if(text[0]=='*') { if(text[1]==')') { text+=2; break; } } text++; } if(!*text)dpp=false; } int balans()/* Test for '(' and ')' */ { int k=0,n=0; while(*text) { if(*text=='(') { text++; if(*text=='*') { text++; comments(); if(dpp==false)return 1; continue; } else {k++;continue;} } else { if(*text==')') n++; } text++; } if (k==n) return 0; else return 1; } int main() { char *txt2,*txt3; text=(char*)malloc(10001); txt3=(char*)malloc(501); memset(txt3,0,sizeof(txt3)); memset(text,0,sizeof(text)); while(!feof(stdin)) { fgets(txt3,500,stdin); strcat(text,txt3); memset(txt3,0,sizeof(txt3));
} txt2=text;
if(balans()==0) { text=txt2;
mloop(); if(dpp) printf("YES"); else printf("NO"); } else printf("NO"); } It's my code... It's not clear... But it work on all test which i found on this discuss...What can be on #8 ? +( Test #8 contains a ')' immediatly after a '('. Re: Show the code. You should change this: void comments() { while(*text) { if(text[0]=='*') { if(text[1]==')') { text+=2; return; } } text++; } dpp=false; } Re: Show the code. Are you crazy? Re: Show the code. Nilrem, Are you crazy? |
|
|