about summary refs log tree commit diff
path: root/daily/285easy/1enc.pas
blob: fb7c3632159296f3255762f7b4f6b228010d60f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(* uuencoding *)

var
  fi, fo: text;
  s: string[3] = 'CnX';
  n: cardinal = 0;
  i: cardinal;
  j: byte;


function enc(s: string): string;
  var
    c1, c2, c3: byte;

  begin
    c1 := ord(s[1]);
    if length(s) < 2 then
      c2 := 0
    else
      c2 := ord(s[2]);
    if length(s) < 3 then
      c3 := 0
    else
      c3 := ord(s[3]);

    enc := chr(c1 div 4 + 32) 
           + chr(c1 mod 4 * 16 + c2 div 16 + 32)
           + chr(c2 mod 16 * 4 + c3 div 64 + 32)
           + chr(c3 mod 64 + 32)
  end;


begin
  assign(fi, '1enc.inp');
  assign(fo, '1enc.out');

  reset(fi);
  while not eof(fi) do
    begin
      read(fi, s[1]);
      inc(n)
    end;
  if n = 0 then
    writeln(fo, ' ');

  reset(fi);
  rewrite(fo);
  for i := 1 to n div 45 do
    begin
      write(fo, 'M');
      for j := 1 to 15 do
        begin
          read(fi, s);
          write(fo, enc(s))
        end;
      writeln(fo);
    end;

  n := n mod 45;
  if n > 0 then
    begin
      write(fo, chr(n + 32));
      for i := 1 to n div 3 do
        begin
          read(fi, s);
          write(fo, enc(s))
        end;
        if n mod 3 > 0 then
          begin
            read(fi, s);
            writeln(fo, enc(s))
          end
        else
          writeln(fo)
    end;

  close(fi);
  close(fo)
end.