commit 7b79356f8dd39479b0b1ba221c2fcd6f4ba7e86b parent d7c68bcc5c243becbe324905bf1b2a4cb08b1690 Author: Dominik Schmidt <das1993@hotmail.com> Date: Thu, 3 Sep 2015 00:00:17 +0200 atoz und shift in D implementiert. Diffstat:
Objects/Program/D/atoz.d | | | 18 | ++++++++++++++++++ |
Objects/Program/D/shift.d | | | 16 | ++++++++++++++++ |
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/Objects/Program/D/atoz.d b/Objects/Program/D/atoz.d @@ -0,0 +1,18 @@ +import std.stdio; +import std.range; +import std.algorithm; + +pure @nogc @safe char char_atoz(char c){ + return cast(char)('z'+'a'-c); +} +pure @nogc @safe char transform(char c){ + if(c>='a' && c<='z'){ + return char_atoz(c); + } + return c; +} + +int main(string args[]){ + writeln(args[1..$].joiner(" ").map!(a=>transform(cast(char)a))); + return 0; +} diff --git a/Objects/Program/D/shift.d b/Objects/Program/D/shift.d @@ -0,0 +1,16 @@ +import std.stdio; +import std.range; +import std.algorithm; + +char caesar(byte off, char c){ + if(c>='a' && c<='z'){ + return cast(char)(c+off); + } + return c; +} + +int main(string args[]){ + byte shift=std.conv.to!byte(args[1]); + writeln(args[2..$].joiner(" ").map!(a=>caesar(shift,cast(char)a))); + return 0; +}