about summary refs log tree commit diff
path: root/daily/285easy/1enc.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-08 09:56:43 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-08 09:56:43 +0700
commit2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0 (patch)
tree95190a32ec1c7098494849eea5a5ba6b53289585 /daily/285easy/1enc.pas
parent207cc2ae9893b0cdecd20119b9ede37f73cd4a1e (diff)
downloadcp-2a7bc10f6c011d19fb3b0e73068f7e1a9c30ace0.tar.gz
Initial commit
Diffstat (limited to 'daily/285easy/1enc.pas')
-rw-r--r--daily/285easy/1enc.pas79
1 files changed, 79 insertions, 0 deletions
diff --git a/daily/285easy/1enc.pas b/daily/285easy/1enc.pas
new file mode 100644
index 0000000..fb7c363
--- /dev/null
+++ b/daily/285easy/1enc.pas
@@ -0,0 +1,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.