using System.Linq;publicclassKata{publicstaticstringEncode(string str)=>Decode(str);publicstaticstringDecode(string str){var s ="GDRPLKgdrplkAEYOUIaeyoui";var t ="AEYOUIaeyouiGDRPLKgdrplk";returnstring.Concat(str.Select(x => s.IndexOf(x)<0? x : t[s.IndexOf(x)]));}}
答案2:
using System;using System.Linq;using System.Collections.Generic;publicstaticclassKata{privatestatic Dictionary<char,char> d =newDictionary<char,char>{{'G','A'},{'A','G'},{'g','a'},{'a','g'},{'D','E'},{'E','D'},{'d','e'},{'e','d'},{'R','Y'},{'Y','R'},{'r','y'},{'y','r'},{'P','O'},{'O','P'},{'p','o'},{'o','p'},{'L','U'},{'U','L'},{'l','u'},{'u','l'},{'K','I'},{'I','K'},{'k','i'},{'i','k'}};publicstaticstringEncode(string s)=>newString(s.Select(c => d.ContainsKey(c)? d[c]: c).ToArray());publicstaticstringDecode(string s)=>Encode(s);}
答案3:
using System;using System.Text;using System.Collections.Generic;publicclassKata{privatestatic Dictionary<char,char> dict =newDictionary<char,char>(){{'G','A'},{'D','E'},{'R','Y'},{'P','O'},{'L','U'},{'K','I'},{'A','G'},{'E','D'},{'Y','R'},{'O','P'},{'U','L'},{'I','K'},{'g','a'},{'d','e'},{'r','y'},{'p','o'},{'l','u'},{'k','i'},{'a','g'},{'e','d'},{'y','r'},{'o','p'},{'u','l'},{'i','k'}};publicstaticstringEncode(string str){StringBuilder sb =newStringBuilder();foreach(char c in str){if(dict.ContainsKey(c)) sb.Append(dict[c]);else sb.Append(c);}return sb.ToString();}publicstaticstringDecode(string str){returnEncode(str);}}
using System;publicclassKata{privatestaticchar[,] letterSwap =newchar[,]{{'g','a'},{'d','e'},{'r','y'},{'p','o'},{'l','u'},{'k','i'}};publicstaticstringEncode(string str){returnEncodeDecode(str);}publicstaticstringDecode(string str){returnEncodeDecode(str);}privatestaticstringEncodeDecode(string str){for(int i =0; i < letterSwap.Length /2; i++){
str = str.Replace(letterSwap[i,0],'~').Replace(letterSwap[i,1], letterSwap[i,0]).Replace('~', letterSwap[i,1]);
str = str.Replace(Char.ToUpper(letterSwap[i,0]),'~').Replace(Char.ToUpper(letterSwap[i,1]), Char.ToUpper(letterSwap[i,0])).Replace('~', Char.ToUpper(letterSwap[i,1]));}return str;}}
答案6:
using System;using System.Collections.Generic;using System.Linq;publicclassKata{publicstatic Dictionary<char,char> d =newDictionary<char,char>{{'g','a'},{'a','g'},{'d','e'},{'e','d'},{'r','y'},{'y','r'},{'p','o'},{'o','p'},{'l','u'},{'u','l'},{'k','i'},{'i','k'}};publicstaticstringEncode(string str){string outStr ="";foreach(char ch in str){if(d.ContainsKey(Char.ToLower(ch))){if(Char.IsUpper(ch))
outStr += Char.ToUpper(d[Char.ToLower(ch)]);else
outStr += d[ch];}else
outStr += ch;}return outStr;}publicstaticstringDecode(string str){returnEncode(str);}}
答案7:
using System.Linq;using System;publicclassKata{publicstaticstringEncode(string str){string cyper ="gaderypolukiGADERYPOLUKI";returnstring.Concat( str.Select(x => cyper.IndexOf(x)==-1? x :((cyper.IndexOf(x)%2==1)? cyper[cyper.IndexOf(x)-1]: cyper[cyper.IndexOf(x)+1])));}publicstaticstringDecode(string str){returnEncode(str);}}
答案8:
publicclassKata{publicstaticstringEncode(string str){string res ="";for(int i=0;i<str.Length;i++){switch(str[i]){case'g': res +="a";break;case'G': res +="A";break;case'd': res +="e";break;case'D': res +="E";break;case'r': res +="y";break;case'R': res +="Y";break;case'p': res +="o";break;case'P': res +="O";break;case'l': res +="u";break;case'L': res +="U";break;case'k': res +="i";break;case'K': res +="I";break;case'a': res +="g";break;case'A': res +="G";break;case'e': res +="d";break;case'E': res +="D";break;case'y': res +="r";break;case'Y': res +="R";break;case'o': res +="p";break;case'O': res +="P";break;case'u': res +="l";break;case'U': res +="L";break;case'i': res +="k";break;case'I': res +="K";break;default: res += str[i];break;}}return res;}publicstaticstringDecode(string str){string res ="";for(int i=0;i<str.Length;i++){switch(str[i]){case'a': res +="g";break;case'A': res +="G";break;case'e': res +="d";break;case'E': res +="D";break;case'y': res +="r";break;case'Y': res +="R";break;case'o': res +="p";break;case'O': res +="P";break;case'u': res +="l";break;case'U': res +="L";break;case'i': res +="k";break;case'I': res +="K";break;case'g': res +="a";break;case'G': res +="A";break;case'd': res +="e";break;case'D': res +="E";break;case'r': res +="y";break;case'R': res +="Y";break;case'p': res +="o";break;case'P': res +="O";break;case'l': res +="u";break;case'L': res +="U";break;case'k': res +="i";break;case'K': res +="I";break;default: res += str[i];break;}}return res;}}
C#练习题答案: TO DE-RY-PO-陆琪暗号【难度:1级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战
TO DE-RY-PO-陆琪暗号【难度:1级】:答案1: using System.Linq; public class Kata { public static string Encode(string str) => Decode(str); public static string Decode(string str) {...