using System;using System.Linq;publicclassKata{publicstaticstringEncode(string str){string alpha ="_abcdefghijklmnopqrstuvwxyz";return String.Concat(str.ToLower().Select((c, i)=> Char.IsLetter(c)?""+(alpha.IndexOf(c)):""+ c));}}
答案2:
using System.Text.RegularExpressions;publicclassKata{publicstaticstringEncode(string str){return Regex.Replace(str,"[a-zA-Z]",s=>str[s.Index]-(str[s.Index]>96?96:64)+"");}}
答案3:
using System;using System.Collections.Generic;publicclassKata{publicstaticstringEncode(string str){string ret =string.Empty;foreach(char chr in str){
ret += Char.IsLetter(chr)?((int)chr %32).ToString(): chr.ToString();}return ret;}}
答案4:
using System;publicclassKata{publicstaticstringEncode(string str){string res ="";foreach(char c in str){if(char.IsLetter(c)&&!char.IsLower(c)){ res+= c -64;}elseif(char.IsLetter(c)&&char.IsLower(c)){ res+= c -96;}else{ res+= c;}}return res;}}
答案5:
using System;using System.Text;publicclassKata{publicstaticstringEncode(string str){StringBuilder sb =newStringBuilder();
str = str.ToLower();for(int i =0; i < str.Length; i++){if(Char.IsLetter(str[i])){string p =(str[i]-96).ToString();
sb.Append(p);}else
sb.Append(str[i]);}return sb.ToString();}}
答案6:
using System;using System.Collections.Generic;publicclassKata{publicstaticstringEncode(string str){
Dictionary<string,int> dictionary =newDictionary<string,int>{{"a",1},{"b",2},{"c",3},{"d",4},{"e",5},{"f",6},{"g",7},{"h",8},{"i",9},{"j",10},{"k",11},{"l",12},{"m",13},{"n",14},{"o",15},{"p",16},{"q",17},{"r",18},{"s",19},{"t",20},{"u",21},{"v",22},{"w",23},{"x",24},{"y",25},{"z",26},};var result ="";foreach(var val in str.ToLower()){if(char.IsLetter(val)){
result += dictionary[val.ToString()];}else{
result += val;}}return result;}}
答案7:
using System;publicclassKata{publicstaticstringEncode(string str){string strResult =string.Empty;foreach(char c in str){if(c >='a'&& c <='z')
strResult +=(c -'a'+1).ToString();elseif(c >='A'&& c <='Z')
strResult +=(c -'A'+1).ToString();else
strResult += c.ToString();}return strResult;}}
答案8:
using System;using System.Linq;publicclassKata{publicstaticstringEncode(string cc){returnstring.Join(string.Empty,
cc.Select(ch =>char.IsLetter(ch)?((ch -(Char.IsLower(ch)?'a':'A'))+1).ToString(): ch.ToString()).ToArray());}}
答案9:
using System.Text.RegularExpressions;publicclassKata{publicstaticstringEncode(string str){return Regex.Replace(str.ToLower(),"[a-z]", m =>((int)char.Parse(m.Value)-96).ToString());}}
答案10:
using System;using System.Linq;publicclassKata{publicstaticstringEncode(string str){returnstring.Concat(str.Select(ch =>{if(char.IsLetter(ch)){
ch =(char)((int)ch |0x0020);return((int)ch -96).ToString();}return ch.ToString();}));}}