makeBackronym  主要考查的是字符串的处理,大小写转换,以及字符串的Linq处理

Description:

Definition-

back·ro·nym

noun

a fanciful expansion of an existing acronym or word, such as “port out, starboard home” for posh.

You will create a function called makeBackronym . There will be a preloaded dictionary to use. The dictionary is an object where the the keys are letters A-Z and the values are a predetermined word.

Use the variable name (its name is written in the code template) to reference the uppercase letters of the dictionary.

EXAMPLE:

dict['P']=="perfect"

There will be a string(without spaces) passed into the function that you need to translate to a Backronym.

The preloaded dictionary can only read uppercase letters, and the value you return will have to be a string.

EXAMPLES:

"dgm" -> "disturbing gregarious mustache"

"lkj" -> "literal klingon joke"
using System;
public partial class Kata
{
public static string MakeBackronym(string s)
{
s = s.ToUpper();
string str = string.Empty;
foreach(var item in s)
{
str += dict[item]+" ";
}
if(str.Equals(string.Empty)==false)
{
str = str.Substring(,str.Length-);
}
return str;
}
}

其他解法:

涉及到string类的静态函数Join

以及string类的方法ToUpper

以及Linq中的select

using System.Linq;

public partial class Kata
{
public static string MakeBackronym(string s)
{
return string.Join(" ", s.ToUpper().Select(c => dict[c]));
}
}
#region 程序集 System.Core.dll, v4.0.0.0
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll
#endregion namespace System.Linq
{
// 摘要:
// 提供一组用于查询实现 System.Collections.Generic.IEnumerable<T> 的对象的 static(在 Visual
// Basic 中为 Shared)方法。
public static class Enumerable { public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector); }
}

makeBackronym的更多相关文章

随机推荐

  1. SSO单点登陆

    一句话,就是能让各个不同的域名带回相同的认证信息即可.实现方法,就是把其中一个登陆后,把认证的信息分别保存在不同域名下的 cookie,当在验证是否登陆时,验证 cookie,如果是子域名,这个则直接 ...

  2. [PHP]set_time_limit — 设置脚本最大执行时间

    (PHP 4, PHP 5) set_time_limit — 设置脚本最大执行时间 说明 void set_time_limit ( int $seconds ) 设置允许脚本运行的时间,单位为秒. ...

  3. Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll

    Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...

  4. ARM-Linux S5PV210 UART驱动(6)----platform device的添加

    开发板是飞凌OK210 arch/arm/mach-s5pv210/mach-smdkc110.c 首先是UART的寄存器默认配置信息: /* Following are default values ...

  5. 【Vmware】已有镜像文件的导入

    1  虚拟机文件夹中各个文件简介 在创建虚拟机的时候会把相关的文件保存到一个文件夹中.我的机器是Windows 7,64位 ,保存的路径是: C:\Users\User\Documents\Virtu ...

  6. 一些shell脚本实例

    在群里也混了不少时间了.总结一些实例 #统计QQ消息里面某个用户改名字的记录# awk -f# 聊改名字记录#特殊例子 例如#2013-11-28 9:23:56 北京-AA-Vip<12345 ...

  7. 2015-4-2的阿里巴巴笔试题:乱序的序列保序输出(bit数组实现hash)

    分布式系统中的RPC请求经常出现乱序的情况.写一个算法来将一个乱序的序列保序输出.例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, ...

  8. Java字符串之性能优化

    基础类型转化成String 在程序中你可能时常会需要将别的类型转化成String,有时候可能是一些基础类型的值.在拼接字符串的时候,如果你有两个或者多个基础类型的值需要放到前面,你需要显式的将第一个值 ...

  9. TCP报头

    源端口和目的端口: 各占16位 ,服务相对应的源端口和目的端口. 序列号: 占32位,它的范围在[0~2^32-1],序号随着通信的进行不断的递增,当达到最大值的时候重新回到0在开始递增.TCP是面向 ...

  10. C# - Lambda 表达式

    Lambda 表达式分为三个部分: 1 参数定义部分.参数是未类型化的,因此编译器可以根据上下文推断出他们的类型. 2 =>运算符,把Lambda表达式的参数与表达式体分开. 3 表达式体. d ...