Case swapping
Case swapping
Description:
Given a string, swap the case for each of the letters.
e.g. CodEwArs --> cODeWaRS
Examples
Kata.Swap("") == ""
Kata.Swap("CodeWars") == "cODEwARS"
Kata.Swap("abc") == "ABC"
Kata.Swap("ABC") == "abc"
Kata.Swap("123235") == "123235"
using System;
using System.Linq; public static class Kata
{
public static string Swap(string str)
{
return string.Join(string.Empty, str.Select(character => char.IsLower(character) ? char.ToUpper(character) : char.IsUpper(character) ? char.ToLower(character) : character));
} //public static string Swap(string str)
//{
// str = string.Join(string.Empty, str.Select(Selector));
// return str; //your code here
//} //public static char Selector(char character)
//{
// char tempCharacter = character;
// if (char.IsLower(character))
// {
// tempCharacter = char.ToUpper(character);
// }
// else if (char.IsUpper(character))
// {
// tempCharacter = char.ToLower(character);
// }
// return tempCharacter;
//}
}
其他人的解法
需要学习的是:char.ToUpper以及char.ToLower本身可以处理非大小写的字符,不需要另外多一个判断
using System;
using System.Linq; public static class Kata {
public static string Swap(string str) {
return String.Concat(str.Select(c => Char.IsUpper(c) ? Char.ToLower(c) : Char.ToUpper(c)));
}
}
Case swapping的更多相关文章
- Swapping
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Referring back to Fig ...
- [POJ 1674] Sorting by Swapping
Sorting by Swapping Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9514 Accepted: 50 ...
- Matrix Swapping II(求矩阵最大面积,dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 第15届浙江省赛 D Sequence Swapping(dp)
Sequence Swapping Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a strange s ...
- HDU 2830 Matrix Swapping II (预处理的线性dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- File System Design Case Studies
SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Int ...
- D:Sequence Swapping
BaoBao has just found a strange sequence {<, >, <, >, , <, >} of length in his poc ...
- C#中,switch case语句中多个值匹配一个代码块的写法
switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...
- Android Studio快捷键switch case 轻松转换为if else
Android Studio快捷键switch case 轻松转换为if else 今天碰到的问题,没有找到资料,后面找到了方法,这个记下来,转载请注明出处:http://www.cnblogs.co ...
随机推荐
- 第十篇、HTML5实战篇——1
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <!--支持IE ...
- 02两栈共享空间_DoubleStack--(栈与队列)
#include "stdio.h" #include "stdlib.h" #include "io.h" #include " ...
- 2016/01/19 javascript学习笔记-name属性
1. name属性只在少数html元素中有效:包括表单.表单元素.<iframe>和<img>元素. 基于name属性的值选取html元素,可以使用document对象的get ...
- EL表达式 入门
为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. JSP EL语言定义 E L(Expression L ...
- 09_TomCat_基础知识
[TomCat目录结构] bin----------存放TomCat的操作命令.bat:window版本,sh:Linux版本. startup.bat: 后台在调用catalina.bat st ...
- ZOJ 1202 Divide and Count(排列组合)
Divide and Count 题目大意:给定箱子的数量和每个箱子的容量,在每个箱子里都装满对应容量的宝石,每颗宝石都是独一无二的,求一共有多少种放置方式.但是如果两个箱子的容量相同,则认为是 同一 ...
- C++ txt文档读取
void readfile(string filepath){ ifstream myfile; if (!myfile) { cout << "打开文件出错!"; e ...
- 第9条:覆盖equals时总要覆盖hashCode
在每个覆盖equals方法的类中,也必须覆盖hashCode方法.否则,会违反Object.hashCode的通用约定,从而导致该类无法结合所有基于散列的集合一起正常工作,包括HashMap,Hash ...
- windows phone 操作 http异步返回结果
wp中为了提升用户体验,砍掉了http的同步操作,仅支持http异步请求,那么该如何及时处理异步操作返回的结果.纠结了很久,终于在技术群中好友的帮助下解决了问题,借助事件,将异步编程模型模式简单的处理 ...
- SharePoint2013TimerJob计时器发送邮件
http://www.3fwork.com/b500/000307MYM008190/