(果然是高手+Grεεκ)案例【难度:2级】:
答案1:
using System;
using System. Collections. Generic;
public class L33TGreekCase
{
public static string GreekL33t ( string str)
{
Dictionary< char , char > dict = new Dictionary < char , char > ( )
{
{ 'a' , 'α' } ,
{ 'b' , 'β' } ,
{ 'd' , 'δ' } ,
{ 'e' , 'ε' } ,
{ 'i' , 'ι' } ,
{ 'k' , 'κ' } ,
{ 'n' , 'η' } ,
{ 'o' , 'θ' } ,
{ 'p' , 'ρ' } ,
{ 'r' , 'π' } ,
{ 't' , 'τ' } ,
{ 'u' , 'μ' } ,
{ 'v' , 'υ' } ,
{ 'w' , 'ω' } ,
{ 'x' , 'χ' } ,
{ 'y' , 'γ' }
} ;
char [ ] letters = str. ToLower ( ) . ToCharArray ( ) ;
for ( int i = 0 ; i < letters. Length; i++ )
{
if ( dict. ContainsKey ( letters[ i] ) )
letters[ i] = dict[ letters[ i] ] ;
}
return string . Join ( "" , letters) ;
}
}
答案2:
public class L33TGreekCase
{
public static string GreekL33t ( string str)
{
for ( int i = 0 ; i < str. Length; i++ )
if ( str[ i] == 'A' || str[ i] == 'a' )
str = str. Replace ( str[ i] , 'α' ) ;
else if ( str[ i] == 'E' || str[ i] == 'e' )
str = str. Replace ( str[ i] , 'ε' ) ;
else if ( str[ i] == 'N' || str[ i] == 'n' )
str = str. Replace ( str[ i] , 'η' ) ;
else if ( str[ i] == 'R' || str[ i] == 'r' )
str = str. Replace ( str[ i] , 'π' ) ;
else if ( str[ i] == 'V' || str[ i] == 'v' )
str = str. Replace ( str[ i] , 'υ' ) ;
else if ( str[ i] == 'Y' || str[ i] == 'y' )
str = str. Replace ( str[ i] , 'γ' ) ;
else if ( str[ i] == 'B' || str[ i] == 'b' )
str = str. Replace ( str[ i] , 'β' ) ;
else if ( str[ i] == 'I' || str[ i] == 'i' )
str = str. Replace ( str[ i] , 'ι' ) ;
else if ( str[ i] == 'O' || str[ i] == 'o' )
str = str. Replace ( str[ i] , 'θ' ) ;
else if ( str[ i] == 'T' || str[ i] == 't' )
str = str. Replace ( str[ i] , 'τ' ) ;
else if ( str[ i] == 'W' || str[ i] == 'w' )
str = str. Replace ( str[ i] , 'ω' ) ;
else if ( str[ i] == 'D' || str[ i] == 'd' )
str = str. Replace ( str[ i] , 'δ' ) ;
else if ( str[ i] == 'K' || str[ i] == 'k' )
str = str. Replace ( str[ i] , 'κ' ) ;
else if ( str[ i] == 'P' || str[ i] == 'p' )
str = str. Replace ( str[ i] , 'ρ' ) ;
else if ( str[ i] == 'U' || str[ i] == 'u' )
str = str. Replace ( str[ i] , 'μ' ) ;
else if ( str[ i] == 'X' || str[ i] == 'x' )
str = str. Replace ( str[ i] , 'χ' ) ;
else
str = str. ToLower ( ) ;
return str;
}
}
答案3:
using System. Collections. Generic;
using System. Linq;
public class L33TGreekCase
{
private static readonly Dictionary< char , char > LatinToGreek = new Dictionary < char , char > ( )
{
{ 'a' , 'α' } , { 'b' , 'β' } , { 'd' , 'δ' } , { 'e' , 'ε' } , { 'i' , 'ι' } , { 'k' , 'κ' } , { 'n' , 'η' } , { 'o' , 'θ' } ,
{ 'p' , 'ρ' } , { 'r' , 'π' } , { 't' , 'τ' } , { 'u' , 'μ' } , { 'v' , 'υ' } , { 'w' , 'ω' } , { 'x' , 'χ' } , { 'y' , 'γ' }
} ;
public static string GreekL33t ( string str)
{
return string . Concat ( ( str ? ? "" ) . ToLower ( ) . Select ( c = > LatinToGreek. Keys. Contains ( c) ? LatinToGreek[ c] : c) ) ;
}
}
答案4:
using System. Collections. Generic;
using System. Linq;
public class L33TGreekCase
{
static Dictionary< char , char > convert = new Dictionary < char , char > ( ) {
{ 'a' , 'α' } ,
{ 'b' , 'β' } ,
{ 'd' , 'δ' } ,
{ 'e' , 'ε' } ,
{ 'i' , 'ι' } ,
{ 'k' , 'κ' } ,
{ 'n' , 'η' } ,
{ 'o' , 'θ' } ,
{ 'p' , 'ρ' } ,
{ 'r' , 'π' } ,
{ 't' , 'τ' } ,
{ 'u' , 'μ' } ,
{ 'v' , 'υ' } ,
{ 'w' , 'ω' } ,
{ 'x' , 'χ' } ,
{ 'y' , 'γ' } ,
} ;
public static string GreekL33t ( string str)
{
return string . Concat ( str. ToLower ( ) . Select ( a = > convert. ContainsKey ( a) ? convert[ a] : a) ) ;
}
}
答案5:
using System;
using System. Collections. Generic;
public class L33TGreekCase
{
public static string GreekL33t ( string str)
{
Dictionary< char , char > alph = new Dictionary < char , char >
{ { 'a' , 'α' } , { 'b' , 'β' } , { 'd' , 'δ' } , { 'e' , 'ε' } , { 'i' , 'ι' } , { 'k' , 'κ' } ,
{ 'n' , 'η' } , { 'o' , 'θ' } , { 'p' , 'ρ' } , { 'r' , 'π' } , { 't' , 'τ' } , { 'u' , 'μ' } ,
{ 'v' , 'υ' } , { 'w' , 'ω' } , { 'x' , 'χ' } , { 'y' , 'γ' } } ;
string res = "" ;
str = str. ToLower ( ) ;
for ( int i = 0 ; i < str. Length; i++ )
{
if ( alph. ContainsKey ( str[ i] ) ) res + = alph[ str[ i] ] ;
else res + = str[ i] ;
}
return res;
}
}
答案6:
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
using System. Threading. Tasks;
public class L33TGreekCase
{
public static string GreekL33t ( string str)
{
var leet = new Dictionary < string , string > ( )
{
{ "a" , "α" } , { "b" , "β" } , { "d" , "δ" } , { "e" , "ε" } ,
{ "i" , "ι" } , { "k" , "κ" } , { "n" , "η" } , { "o" , "θ" } ,
{ "p" , "ρ" } , { "r" , "π" } , { "t" , "τ" } , { "u" , "μ" } ,
{ "v" , "υ" } , { "w" , "ω" } , { "x" , "χ" } , { "y" , "γ" }
} ;
var final = "" ;
string temp;
foreach ( var c in str)
{
if ( leet. TryGetValue ( c. ToString ( ) . ToLower ( ) , out temp) )
{
final + = temp;
}
else
{
final + = c. ToString ( ) . ToLower ( ) ;
}
}
return final;
}
}
答案7:
public class L33TGreekCase
{
public static string GreekL33t ( string str)
= > str. ToLower ( )
. Replace ( "a" , "α" )
. Replace ( "e" , "ε" )
. Replace ( "n" , "η" )
. Replace ( "r" , "π" )
. Replace ( "v" , "υ" )
. Replace ( "y" , "γ" )
. Replace ( "b" , "β" )
. Replace ( "i" , "ι" )
. Replace ( "o" , "θ" )
. Replace ( "t" , "τ" )
. Replace ( "w" , "ω" )
. Replace ( "d" , "δ" )
. Replace ( "k" , "κ" )
. Replace ( "p" , "ρ" )
. Replace ( "u" , "μ" )
. Replace ( "x" , "χ" ) ;
}
答案8:
public class L33TGreekCase
{
public static string GreekL33t ( string str)
{
return str. ToUpper ( )
. Replace ( "A" , "α" )
. Replace ( "E" , "ε" )
. Replace ( "N" , "η" )
. Replace ( "R" , "π" )
. Replace ( "V" , "υ" )
. Replace ( "Y" , "γ" )
. Replace ( "B" , "β" )
. Replace ( "I" , "ι" )
. Replace ( "O" , "θ" )
. Replace ( "T" , "τ" )
. Replace ( "W" , "ω" )
. Replace ( "D" , "δ" )
. Replace ( "K" , "κ" )
. Replace ( "P" , "ρ" )
. Replace ( "U" , "μ" )
. Replace ( "X" , "χ" )
. ToLower ( ) ;
}
}
答案9:
using System. Linq;
using System. Collections. Generic;
public class L33TGreekCase
{
static readonly Dictionary< char , char > Map = "aα eε nη rπ vυ yγ bβ iι oθ tτ wω dδ kκ pρ uμ xχ"
. Split ( ) . ToDictionary ( x = > x. First ( ) , x = > x. Last ( ) ) ;
public static string GreekL33t ( string str) = > string . Concat ( str. ToLower ( ) . Select ( GreekL33tChar) ) ;
public static char GreekL33tChar ( char chr) = > Map. ContainsKey ( chr) ? Map[ chr] : chr;
}
答案10:
using System. Linq;
public class L33TGreekCase
{
const string a = "αβcδεfghιjκlmηθρqπsτμυωχγz" ;
public static string GreekL33t ( string str) = > string . Concat ( str. ToLower ( ) . Select ( x = > char . IsLetter ( x) ? a[ x - 97 ] : x) ) ;
}