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的更多相关文章

  1. B. Order Book(Codeforces Round #317 )

    B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. UNION All中ORDER By的使用

    一个sql中,union了几个子查询.单独执行每个子查询都没问题,但union后执行,报ORA-00904: "xxx": invalid identifier关于union的使用 ...

  3. C# 完整List例子

    C# List Following examples show how to create and manipulate with .NET strongly typed list List<T ...

  4. RESTful API 设计最佳实践

    背景 目前互联网上充斥着大量的关于RESTful API(为了方便,以后API和RESTful API 一个意思)如何设计的文章,然而却没有一个"万能"的设计标准:如何鉴权?API ...

  5. AngularJS之Filter(二)

    前言 本节我们来讲讲AngularJS中主要的部分之一,那就是过滤器,当从后台获取到的数据呈现到视图上时,此时可能需要对数据进行相应的转换,此时我们可以通过过滤器在不同页面进行不同数据的格式抓换,在A ...

  6. HBase 数据模型(Data Model)

    HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...

  7. .NET LINQ 数据排序

    数据排序      排序操作按一个或多个特性对序列的元素进行排序. 第一个排序条件对元素执行主要排序. 通过指定第二个排序条件,可以对各个主要排序组中的元素进行排序.   方法 方法名 说明 C# 查 ...

  8. Design and Analysis of Algorithms_Decrease-and-Conquer

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  9. 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 ...

随机推荐

  1. DTCMS更改图片相册上传图片类型,手机上传图片相册

    /admin/js/uploader.js 中 filetypes: "jpg,jpge,png,gif", //文件类型 改为 filetypes: "jpg,jpeg ...

  2. 【转】DataGridView绑定数据源的几种方式

    第一种:DataSet ds=new DataSet (); this.dataGridView1.DataSource=ds.Table[0]; 第二种:DataTable dt=new DataT ...

  3. 漫谈php全局变量Global

    global语句的作用是定义全局变量,例如如果想在函数内访问全局作用域内的变量则可以通过global声明来定义. 下面从语法解释开始分析. 1. 词法解析 查看 Zend/zend_language_ ...

  4. EXTJS4.2 控件之Grid 根据数据源某列数据不同绑定不同的控件setEditor

    Grid 根据数据源某列数据不同绑定不同的控件,例如:文本框和下拉框 主要代码写在grid的  plugins: [rowEditing],下面这是定义的rowEditing对象,这里面的要定义成 E ...

  5. Android Studio 单刷《第一行代码》系列 05 —— Fragment 基础

    前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...

  6. bnu 4359 无爱编号(规律)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4359 [题意]:输入N,表示几位数,0-这个N位数,有多少个满足条件的号码,不满足的情况为出现4,1 ...

  7. LNMP笔记:更改网站文件和MySQL数据库的存放目录

    配置好LNMP环境以后,默认的网站目录和数据库存放目录都在系统盘,所以我们需要将它们转移到数据盘. 更改网站文件目录 如果你使用的是军哥的lnmp一键安装包,那默认的虚拟主机配置环境在 /usr/lo ...

  8. 三年PS经验

  9. HZNU1015: 矩阵排序

    http://acm.hznu.edu.cn/JudgeOnline/problem.php?id=1015 题意:把矩阵每一行都排序. (以前觉得很难的题目回头看看原来如此简单 ][]; ; i&l ...

  10. 软考类----编码、ASII码等

    淘米2014实习生笔试,今年是淘米第一年招暑期实习生,笔试好大部分考的是软考的题目啊啊啊啊(劳资后悔当年没考软考刷加权),其他是浅而泛的风格,C++,SQL语句,数据结构(哈夫曼树,二叉查找树,栈后缀 ...