|
|
вернуться в форумPlease help me with this problem. This problem seems so easy but it isn't so easy. I'll be thankful to anyone who will find mistake in my program or give me some tests var a:array[1..10001] of char; ch:char; n:integer; skobka,comm:boolean; nsk:integer; i:integer; procedure readdata; begin n:=0; while not eof do begin inc(n); read(ch); a[n]:=ch; end; end; function check(ch:char):boolean; begin if (ch in ['0'..'9']) or (ch in ['=','+','-','*','/']) then check:=true else check:=false; end; begin readdata; skobka:=false; comm:=false; for i:=1 to n do if (comm) and (a[i]='*') and (a[i+1]=')') then begin comm:=false; inc(i); end else if (not comm) and (a[i]='(') and (a[i+1]='*') then begin comm:=true; inc(i); end else if comm then begin end else if (not skobka) and (a[i]='(') then begin skobka:=true; nsk:=1; end else if (skobka) and (a[i]=')') then begin dec(nsk); if nsk=0 then begin skobka:=false; nsk:=-maxint; end; end else if (skobka) and (a[i]='(') then begin inc(nsk); end else if ((skobka) and (not check(a[i]))) or ( (not skobka) and (a[i]='*') and (a[i+1]=')') and (not comm)) then begin writeln('NO'); halt; end else if (nsk<0) and (nsk<>-maxint)then begin writeln('NO'); halt; end; if (comm) or (skobka) then writeln('NO') else writeln('YES'); end. Re: Please help me with this problem. Послано Kit 11 апр 2005 12:12 Try this: There is something wro)ng. Your answer is "YES". You should read problems more attentively. Re: Please help me with this problem. Yes, you are right. Here is code which gives correct answer for your test, but it still gets WA#1 ! Please look over my code again. var a:array[1..10001] of char; ch:char; n:integer; skobka,comm:boolean; nsk:integer; i:integer; procedure readdata; begin {assign(input,'in.in'); reset(input);} n:=0; while not eof do begin inc(n); read(ch); a[n]:=ch; end; {close(input);} end; function check(ch:char):boolean; begin if (ch in ['0'..'9']) or (ch in ['=','+','-','*','/']) then check:=true else check:=false; end; begin readdata; skobka:=false; comm:=false; for i:=1 to n do if (comm) and (a[i]='*') and (a[i+1]=')') then begin comm:=false; inc(i); end else if (not comm) and (a[i]='(') and (a[i+1]='*') then begin comm:=true; inc(i); end else if comm then begin end else if (not skobka) and (a[i]='(') then begin skobka:=true; nsk:=1; end else if (skobka) and (a[i]=')') then begin dec(nsk); if nsk=0 then begin skobka:=false; nsk:=-maxint; end; end else if (skobka) and (a[i]='(') then begin inc(nsk); end else if ((skobka) and (not check(a[i]))) or ( (not skobka) and (a[i]='*') and (a[i+1]=')') and (not comm)) then begin writeln('NO'); halt; end else if (nsk<0) and (nsk<>-maxint)then begin writeln('NO'); halt; end else if (not skobka) and (a[i]=')') then begin writeln('NO'); halt; end ; if (comm) or (skobka) then writeln('NO') else writeln('YES'); end. Re: Please help me with this problem. Послано Kit 11 апр 2005 18:41 For example: (1+ 2) Your answer is "NO". In order to avoid it, you should use in readdata something like this (if you read characters, not numbers): while eoln and not eof do readln; Good luck! Re: Please help me with this problem. Thank you very much, I changed my code a little and at least get AC! Your advice helped me a lot, I changed my prog another way but this test helped to me! Thank you very much! Thanks to Allah! Re: Please help me with this problem. Послано Sid 20 июл 2005 11:11 Try this: There is something wro)ng. Your answer is "YES". You should read problems more attentively. It's a realy good hint! |
|
|