C#练习题答案: (果然是高手+Grεεκ)案例【难度:2级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

(果然是高手+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));
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值