Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Multiples;
- begin
- while (true) do begin
- var NUM, ERR, LEN, CHR: Integer;
- var MAX, IND, SUM: LongInt;
- var STR: String;
- var OKE: Boolean;
- // read max
- write('Enter MAX number: ');
- readln(STR);
- val(STR, MAX, ERR);
- if (ERR <> 0) then begin
- write('Error! ');
- continue;
- end;
- // read num
- write('Enter NUM number: ');
- readln(STR);
- val(STR, NUM, ERR);
- if (ERR <> 0) then begin
- write('Error! ');
- continue;
- end;
- // check
- if (MAX > 0) and (NUM > 1) then begin
- writeln('Working...');
- // set sum and file
- SUM := 0;
- var OUT: TextFile;
- AssignFile(OUT, MAX + '-' + NUM + '.txt');
- rewrite(OUT);
- // begin loop
- for IND := 1 to MAX do begin
- STR := IntToStr(IND);
- LEN := Length(STR);
- // length num or more
- if (LEN >= NUM) then begin
- OKE := TRUE;
- // check last num symbols
- for CHR := 1 to (NUM-1) do if (STR[LEN-CHR] <> STR[LEN]) then OKE := FALSE;
- // check one mone symbol
- if (LEN > NUM) and (STR[LEN-NUM] = STR[LEN]) then OKE := FALSE;
- // nice
- if OKE then begin
- writeln(OUT, STR);
- SUM := SUM + 1;
- end;
- end;
- end;
- // close
- CloseFile(OUT);
- write('Done! SUM = ', SUM, '. Press ENTER.');
- readln;
- end else write('Error! ');
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement