Descending Order
Descending Order
Description:
Your task is to make a function that can take any non-negative integer as a argument and return it with it's digits in descending order. Descending order means that you take the highest digit and place the next highest digit immediately after it.
Examples:
Input: 145263 Output: 654321
Input: 1254859723 Output: 9875543221
using System;
using System.Linq; public static class Kata
{
public static int DescendingOrder(int num)
{
// Bust a move right here
return Convert.ToInt32(string.Join(string.Empty, num.ToString().OrderBy(c => c).Reverse()));
}
}
其他人的解法:值得学习的是,str本身自带了降序排列的函数
关于string.Join以及string.Concat的区别http://www.cnblogs.com/chucklu/p/4621996.html
using System;
using System.Linq; public static class Kata
{
public static int DescendingOrder(int num)
{
return int.Parse(string.Concat(num.ToString().OrderByDescending(x => x)));
}
}
Descending Order的更多相关文章
- B. Order Book(Codeforces Round #317 )
B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- UNION All中ORDER By的使用
一个sql中,union了几个子查询.单独执行每个子查询都没问题,但union后执行,报ORA-00904: "xxx": invalid identifier关于union的使用 ...
- C# 完整List例子
C# List Following examples show how to create and manipulate with .NET strongly typed list List<T ...
- RESTful API 设计最佳实践
背景 目前互联网上充斥着大量的关于RESTful API(为了方便,以后API和RESTful API 一个意思)如何设计的文章,然而却没有一个"万能"的设计标准:如何鉴权?API ...
- AngularJS之Filter(二)
前言 本节我们来讲讲AngularJS中主要的部分之一,那就是过滤器,当从后台获取到的数据呈现到视图上时,此时可能需要对数据进行相应的转换,此时我们可以通过过滤器在不同页面进行不同数据的格式抓换,在A ...
- HBase 数据模型(Data Model)
HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...
- .NET LINQ 数据排序
数据排序 排序操作按一个或多个特性对序列的元素进行排序. 第一个排序条件对元素执行主要排序. 通过指定第二个排序条件,可以对各个主要排序组中的元素进行排序. 方法 方法名 说明 C# 查 ...
- Design and Analysis of Algorithms_Decrease-and-Conquer
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- Leetcode: Matchsticks to Square && Grammar: reverse an primative array
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
随机推荐
- discuz论坛X3升级时 文件下载出现问题,请查看您的服务器网络以及data目录是否有写权限
discuz论坛2.5升级X3时候, 在线升级一半提示: 文件 static/image/postbg/3.jpg 下载出现问题,请查看您的服务器网络以及data目录是否有写权限,请确认无误后点击确定 ...
- MySQL定时检查是否宕机并邮件通知
我们有时候需要一些检查MySQL是否宕机,如果宕机了应自动重新启动应用并通知运维人员!此脚本用来简单的实现MySQL宕机后自动重启并邮件通知运维,此为SHELL脚本,当然也有一些朋友喜欢用Python ...
- php安全设定
nginx: 在配置文件nginx.conf的http段里加入 server_tokens off; HTTPD.CONFTraceEnable Off <Directory ~ " ...
- PHP定时执行任务/Cron Job
对于PHP本身并没有一套解决方案来执行定时任务,不过是借助sleep函数完成的.这种方就是要提前做一些配置,如实现过程: ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执 ...
- IP HELPER GetAdaptersAddresses 函数
自己做的一些笔记,XP以及以后的系统使用: MSDN 函数:http://msdn.microsoft.com/en-US/library/windows/desktop/aa365915(v=vs. ...
- Python入门二:函数
一.函数的定义和使用 1.基本结构: def 函数名(参数): """ 文档字符串 """ 函数体 返回值 2.函数名: 和变量名命名规则一 ...
- python 控制台输出中文乱码问题
乱码原因: 源码文件的编码格式为utf-8,但是window的本地默认编码是gbk,所以在控制台直接打印utf-8的字符串当然是乱码了! 解决方法: 1,print mystr.decode('utf ...
- wxPython 基本框架与运行原理 -- App 与 Frame
<wxPython in Action> chapter 1.2 笔记 wxPython 是 wxWidgets 的 Python 实现,“w” for Microsoft Windows ...
- cocos2dx之C++调用Lua
原文地址:http://blog.csdn.net/dingkun520wy/article/details/49839701 1.引入头文件 #include "cocos2d.h&quo ...
- 微软职位内部推荐-Sr SDE-MOD-Beijing
微软近期Open的职位: JOB TITLE: Senior Software Design EngineerDEPARTMENT: Microsoft Office Division ChinaIM ...