ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1027. Снова D++

Please help me with this problem.
Послано Akshin Salimov 11 апр 2005 01:57
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.
Послано Akshin Salimov 11 апр 2005 16:23
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.
Послано Akshin Salimov 12 апр 2005 22:07
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
Kit писал(a) 11 апреля 2005 12:12
Try this:

There is something wro)ng.

Your answer is "YES". You should read problems more attentively.
It's a realy good hint!