Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
55
Добавлен:
10.05.2014
Размер:
2.5 Кб
Скачать
program ticket;
type
str_symbols = string[10];
str_message = string[40];
str11 = string[11];
str1 = string[1];
const
TICKET_LENGTH = 6;
SKIP_HEAD = '';

function get_string(message:str_message):str11;
var
response:str11;
begin
write(message,': ');
readln(response);
get_string:=response;
end;
procedure open_file(file_name:str11;var opened_file:text);
begin
assign(opened_file,file_name);
rewrite(opened_file);
end;

function is_lucky(ticket:str_symbols):boolean;
var
sum:shortint;
current_digit:byte;
i:byte;
code:integer;
begin
sum:=0;
for i:=1 to length(ticket)do{¤«п Є ¦¤®Ј® бЁ¬ў®«  бва®ЄЁ}
begin
val(copy(ticket,i,1),current_digit,code);
if(i<=(length(ticket) div 2))then{Ґб«Ё ®­ ў ЇҐаў®© з бвЁ бва®ЄЁ}
sum:=sum+current_digit{ЇаЁЎ ў«пҐ¬ жЁдаг Є б㬬Ґ}
else{Ё­ зҐ}
sum:=sum-current_digit;{ўлзЁв Ґ¬ жЁдаг Ё§ б㬬л}
end;
is_lucky:=sum=0;{ЎЁ«Ґв бз бв«Ёўл©, Ґб«Ё б㬬  =0}
end;
procedure list_tickets(var file_out:text;head,tail:str_symbols;var count:longint);
var
new_head,new_tail:str_symbols;
i:byte;
current_symbol:str1;
begin
if(length(head)<TICKET_LENGTH)then{Ґб«Ё ­Ґ ¤®бвЁЈ­гв  вॡ㥬 п ¤«Ё­  ЎЁ«Ґв }
begin
for i:=1 to length(tail) do{¤«п Є ¦¤®Ј® бЁ¬ў®«  Ё§ еў®бв }
begin
current_symbol:=copy(tail,i,1);
if(pos(current_symbol,head)=0) and not ((length(head)=0) and (pos(current_symbol,SKIP_HEAD)<>0))then{Ґб«Ё ¤ ­­®Ј® бЁ¬ў®« 
­Ґвг ў Ј®«®ўҐ Ё ®­ ­Ґ ЇҐаўл© ­®«м}
begin
new_head:=head+current_symbol;{¤®Ў ў«пҐ¬ бЁ¬ў®« Є Ј®«®ўҐ}
new_tail:=tail;{г¤ «пҐ¬ бЁ¬ў®« Ё§ еў®бв }
delete(new_tail,i,1);
list_tickets(file_out,new_head,new_tail,count);{®Ўа Ў влў Ґ¬ ­®ўл© еў®бв Ё Ј®«®ўг ४габЁў­®}
end;
end;
end
else{Ё­ зҐ}
begin
if(is_lucky(head))then{Ґб«Ё ЎЁ«Ґв бз бв«Ёўл©}
begin
writeln(file_out,head);{ўлў®¤Ё¬ ЎЁ«Ґв}
count:=count+1;{бзЁв Ґ¬ ҐЈ®}
end;
end;
end;

var
file_name:str11;
file_out:text;
count:longint;
begin
count:=0;
file_name:=get_string('‚ўҐ¤ЁвҐ Ё¬п д ©«  ¤«п ўлў®¤ ');{Ї®«гз Ґ¬ Ё¬п д ©«  ¤«п ўлў®¤ }
open_file(file_name,file_out);{®вЄалў Ґ¬ д ©«}
list_tickets(file_out,'','0123456789',count);{४габЁў­® ўлў®¤Ё¬ ЎЁ«Ґвл}
writeln('Ќ ©¤Ґ­® ',count,' бз бв«Ёўле ЎЁ«Ґв®ў');{ЇҐз в Ґ¬ Є®«ЁзҐбвў® ЎЁ«Ґв®ў}
close(file_out);{§ Єалў Ґ¬ д ©«}
write('Ќ ¦¬Ё ENTER ¤«п ўл室  Ё Ї®б¬®ваЁ ',file_name);
readln;
end.
Соседние файлы в папке 02