011.

( - 1 ., - 16 )

. , - , . , , : . , HH H2. , - , - . . , . , . , - , .

input.txt , . , , , - ( ). 1000 .

output.txt YES, NO, .

input.txt

output.txt

1

OHNaOHNa

YES

2

H2O

YES

3

HH

NO

4

CHC

YES

.

$o-,q+,r+,c-}

$MINSTACKSIZE $00400000}

$APPTYPE console}

uses

math, sysutils;

type

int = longint;

const

maxn = 1000;

START = 0;

ELEMENT_1 = 1;

ELEMENT_2 = 2;

NUMBER = 3;

procedure outno;

begin

write('NO');

halt;

end;

var

lastel: string;

curel: string;

procedure newel(ch: char);

begin

if (curel = lastel) then

outno;

lastel := curel;

curel := ch;

end;

var

ch: char;

r: int;

state: int;

isone: boolean;

begin

reset(input, 'input.txt');

rewrite(output, 'output.txt');

state := START;

r := 0;

isone := false;

lastel := '';

curel := '';

while (not eoln) do begin

read(ch);

assert( (('A' <= ch) and (ch <= 'Z'))

or (('a' <= ch) and (ch <= 'z'))

or (('0' <= ch) and (ch <= '9'))

);

inc(r);

case state of

START: begin

if not (('A' <= ch) and (ch <= 'Z')) then

outno;

curel := ch;

state := ELEMENT_1;

end;

ELEMENT_1: begin

if (('A' <= ch) and (ch <= 'Z')) then begin

newel(ch);

state := ELEMENT_1;

end else if (('0' <= ch) and (ch <= '9')) then begin

if (ch = '0') then

outno;

state := NUMBER;

isone := (ch = '1');

end else begin

curel := curel + ch;

state := ELEMENT_2;

end;

end;

ELEMENT_2: begin

if (('A' <= ch) and (ch <= 'Z')) then begin

newel(ch);

state := ELEMENT_1;

end else if (('0' <= ch) and (ch <= '9')) then begin

if (ch = '0') then

outno;

state := NUMBER;

isone := (ch = '1');

end else begin

outno;

end;

end;

NUMBER: begin

if (('A' <= ch) and (ch <= 'Z')) then begin

if isone then

outno;

newel(ch);

state := ELEMENT_1;

isone := false;

end else if (('0' <= ch) and (ch <= '9')) then begin

state := NUMBER;

isone := false;

end else begin

outno;

end;

end;

end;

end;

if isone or (curel = lastel) then

outno;

assert(r <= maxn);

assert(eof);

write('YES');

end.

 

,

 

- -, 2008-2009 . , 1-

36%

, http://acmu.ru/index.asp?main=task&id_task=420

Rar

, .., 22.05.2012