namespace myjinxin
{using System;publicclassKata{publicstringChessEncryption(string msg){string chess ="v11u21t31s41r51q61p71o81w12x22y32z42k52l62m72n82a43j53b44i54c45h55d46g56e47f57";string res ="";foreach(char ele in msg){if(ele ==' ') res +=' ';else{string temp = chess.Substring(chess.IndexOf(ele)+1,2);char a =(char)(temp[0]-48+96);char b = temp.Substring(1)[0];
res +=(a +""+ b);}}return res;}}}
namespace myjinxin
{using System;using System.Collections.Generic;publicclassKata{publicstringChessEncryption(string msg){
Dictionary<char,string> dict =newDictionary<char,string>(){{'a',"d3"},{'b',"d4"},{'c',"d5"},{'d',"d6"},{'e',"d7"},{'f',"e7"},{'g',"e6"},{'h',"e5"},{'i',"e4"},{'j',"e3"},{'k',"e2"},{'l',"f2"},{'m',"g2"},{'n',"h2"},{'o',"h1"},{'p',"g1"},{'q',"f1"},{'r',"e1"},{'s',"d1"},{'t',"c1"},{'u',"b1"},{'v',"a1"},{'w',"a2"},{'x',"b2"},{'y',"c2"},{'z',"d2"}};
List<string> result =newList<string>();for(int i =0; i < msg.Length; i++){if(dict.ContainsKey(msg[i]))
result.Add(dict[msg[i]]);else
result.Add(msg[i].ToString());}returnstring.Join("", result);}}}
答案4:
namespace myjinxin {using System.Collections.Generic;using System.Text;publicclassKata{privatestatic Dictionary<char,string> _map =newDictionary<char,string>{{'a',"d3"},{'b',"d4"},{'c',"d5"},{'d',"d6"},{'e',"d7"},{'f',"e7"},{'g',"e6"},{'h',"e5"},{'i',"e4"},{'j',"e3"},{'k',"e2"},{'l',"f2"},{'m',"g2"},{'n',"h2"},{'o',"h1"},{'p',"g1"},{'q',"f1"},{'r',"e1"},{'s',"d1"},{'t',"c1"},{'u',"b1"},{'v',"a1"},{'w',"a2"},{'x',"b2"},{'y',"c2"},{'z',"d2"}};publicstringChessEncryption(string msg ){var message =newStringBuilder( msg.Length*2);foreach(var c in msg ){var l =char.ToLower( c );if( _map.ContainsKey( l )){
message.Append( _map [ l ]);}else{
message.Append( c );}}return message.ToString();}}}
答案5:
namespace myjinxin
{using System;publicclassKata{publicstringChessEncryption(string msg){char[][] letters =newchar[][]{newchar[2]{'v','w'},newchar[2]{'u','x'},newchar[2]{'t','y'},newchar[7]{'s','z','a','b','c','d','e'},newchar[7]{'r','k','j','i','h','g','f'},newchar[2]{'q','l'},newchar[2]{'p','m'},newchar[2]{'o','n'}};string retstring ="";foreach(char c in msg){if(c ==' ') retstring +=" ";else{for(int col =0; col <8; col++){for(int row =0; row < letters[col].Length; row++){if(c == letters[col][row]) retstring +=((char)(col +(int)'a')).ToString()+((char)(row +(int)'1')).ToString();}}}}return retstring;}}}
答案6:
namespace myjinxin
{using System;using System.Collections.Generic;using System.Linq;publicclassKata{publicreadonly Dictionary<char,string> Data =newDictionary<char,string>{{'a',"d3"},{'b',"d4"},{'c',"d5"},{'d',"d6"},{'e',"d7"},{'f',"e7"},{'g',"e6"},{'h',"e5"},{'i',"e4"},{'j',"e3"},{'k',"e2"},{'l',"f2"},{'m',"g2"},{'n',"h2"},{'o',"h1"},{'p',"g1"},{'q',"f1"},{'r',"e1"},{'s',"d1"},{'t',"c1"},{'u',"b1"},{'v',"a1"},{'w',"a2"},{'x',"b2"},{'y',"c2"},{'z',"d2"},{' '," "}};publicstringChessEncryption(string msg){//coding and coding..returnstring.Concat(msg.Select(p => Data[p]));}}}
答案7:
namespace myjinxin
{using System;using System.Collections.Generic;using System.Text;publicclassKata{publicstringChessEncryption(string msg){
Dictionary<char,string> letters =newDictionary<char,string>(){{'a',"d3"},{'b',"d4"},{'c',"d5"},{'d',"d6"},{'e',"d7"},{'f',"e7"},{'g',"e6"},{'h',"e5"},{'i',"e4"},{'j',"e3"},{'k',"e2"},{'l',"f2"},{'m',"g2"},{'n',"h2"},{'o',"h1"},{'p',"g1"},{'q',"f1"},{'r',"e1"},{'s',"d1"},{'t',"c1"},{'u',"b1"},{'v',"a1"},{'w',"a2"},{'x',"b2"},{'y',"c2"},{'z',"d2"},{' '," "}};StringBuilder builder =newStringBuilder();foreach(char s in msg){
builder.Append(letters[s]);}return builder.ToString();}}}
答案8:
namespace myjinxin
{using System;publicclassKata{publicstringChessEncryption(string msg){string result ="";string[] encrypted =newstring[]{"d3","d4","d5","d6","d7","e7","e6","e5","e4","e3","e2","f2","g2","h2","h1","g1","f1","e1","d1","c1","b1","a1","a2","b2","c2","d2"};for(int i =0; i < msg.Length; i++){if(msg[i]>=97&& msg[i]<=122){
result += encrypted[msg[i]-97];}else{ result += msg[i];}}return result;}}}