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)));
  }
}
时间: 2024-10-14 02:11:45

Case swapping的相关文章

HDU 2830 Matrix Swapping II (预处理的线性dp)

Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1430    Accepted Submission(s): 950 Problem Description Given an N * M matrix with each entry equal to 0 or 1. We can find som

[POJ 1674] Sorting by Swapping

Sorting by Swapping Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9514   Accepted: 5094 Description Given a permutation of numbers from 1 to n, we can always get the sequence 1, 2, 3, ..., n by swapping pairs of numbers. For example, i

File System Design Case Studies

SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Introduction We've studied various approaches to file system design. Now we'll look at some real file systems to explore the approaches that were taken i

HDU 2830 Matrix Swapping II (DP,最大全1矩阵)

题意  给你一个n*m矩阵  每列都可以随便交换位置   求最优交换后最大的全1子矩阵 又是HDU 1505 1506的变种  但这个更容易了  因为每列都可以交换位置了   那么这一行中所有比i高的都可以与i相邻了  只需要统计这一行有多少个比i高就行了   可以在算出每一行后  把高度大的放前面去  用num[i]记录排序后的列原来的数  这样就有j列比h[i][num[j]]高了  最后的答案也就是max(j*h[i][num[j]]) #include<cstdio> #include

UVA 299- Train Swapping(冒泡排序中交换次数)

Train Swapping Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Train Swapping  At an old railway station, you may still encounter one of the last remaining ``train swappers''. A train swapper is an em

Matrix Swapping II(求矩阵最大面积,dp)

Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1543    Accepted Submission(s): 1036 Problem Description Given an N * M matrix with each entry equal to 0 or 1. We can find so

Swapping

COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Referring back to Figure 8.11, we have discussed three types of queues: the long- term queue of requests for new processes, the short-term queue of processes ready to use

WARNING: Heavy swapping observed on system in last 5 mins.

今天在巡检alert日志的时候,发现如下报错: pct of memory swapped in [7.16%] pct of memory swapped out [0.56%]. Please make sure there is no memory pressure and the SGA and PGA are configured correctly. Look at DBRM trace file for more details. 这个是我在AIX上面新装的RAC,查看metali

HDU 2830 Matrix Swapping II (最大完全子矩阵之可移动列)

Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1210    Accepted Submission(s): 804 Problem Description Given an N * M matrix with each entry equal to 0 or 1. We can find som