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. android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."!

    可以用以下办法解决: 使用SDK Manager更新时出现问题 Failed to fetch URL https://dl-ssl.google.com/android/repository/rep ...

  2. Jquery mobile 学习笔记

    最近学习移动开发,接触到了phonegap,然后又需要开始学习jquery mobile.掌握两者是开发轻应用的前提 在学习jquery mobile中,遇到了许多问题让初学者很是头疼,无意间找到这个 ...

  3. asp:HyperLink vs asp:LinkButton

    asp:HyperLink NavigateUrl - 页面刷新为新的页面 pageload ispostback = false asp:LinkButton PostbackUrl - postb ...

  4. undefined local variable or method ‘xxx’ for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xbc88d6c>错误解决方案

    官方文档如下: https://github.com/rspec/rspec-rails/blob/master/Capybara.md Capybara 2.0 To use Capybara 2. ...

  5. soinn

    Growing Cell Structures A Self-Organizing Network for Unsupervised and Supervised Learning Here, and ...

  6. javascript dom追加内容的例子

    javascript dom追加内容的使用还是比较广泛的,在本文将为大家介绍下具体的使用方法. 例子: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

  7. Django Tutorial 学习笔记

    实际操作了Django入门教程中的范例,对一些细节有了更清晰的掌握.感觉只看文档不动手是不行的,只看文档没法真正掌握其中要素之间的关系,看了很多遍也不行,必须动手做了才能掌握.同时,这次练习在Ecli ...

  8. Oracle 动态视图1 V$LOCK

    v$lock显示数据库当前持有锁情况 Column Datatype Description SID NUMBER 会话ID TYPE VARCHAR2(2) 表示锁的类型.值包括TM,TX,等 ID ...

  9. ISoft(开源)专用下载器

    继 两年的坚持,最后还是决定将ISoft开源 之后,今天再共享一款ISoft专用下载器小工具.这款工具是一年前开发的,也是一直闲置着没去扩展更新.当时开发出来就是仿穿越火线专用下载器的样式来做的,现在 ...

  10. java第三课:分支结构、循环结构

    分支结构 1.if后面可以不加{},但是不建议,容易产生误解2.写程序的时候先防屌丝测试,再写逻辑,否则会出错3.if:一条分支 if else:两条分支 if...else if...:多条分支(结 ...