zoukankan      html  css  js  c++  java
  • 第2关:数据排序

    任务描述

    本关任务:将十个数进行从大到小的顺序进行排列。

    编写程序,从键盘对数组的前n个数组元素依次赋值,并按照从大到小的顺序进行排列输出。

    如:从键盘输入n的值是10,输入的数组元素数据依次是:0,1,2,3,4,5,6,7,8,9,则输出为:9,8,7,6,5,4,3,2,1,0

    注意:n的值应为小于10的正整数,否则输出input error!

    编程提示

    假设数组名为a,则数组元素的输出格式建议采用如下格式:

    Console.Write("{0} ",a[i]);

    输入

    输入n个整数

    输出

    以从大到小的顺序输出这个十个数

    样例输入

    10

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    样例输出

    10 9 8 7 6 5 4 3 2 1


    开始你的任务吧,祝你成功!

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ch702
    {
        class Program
        {
            static void Main(string[] args)
            {
    			/******begin*******/
    			int n = Convert.ToInt32(Console.ReadLine());
                if (n < 0 || n > 10)
                {
                    Console.WriteLine("input error!");
                    return ;
                }
                int[] a = new int[n];
                for (int i = 0; i < n; ++i)
                {
                    a[i] = Convert.ToInt32(Console.ReadLine());
                }
    			Array.Sort(a);
    			for (int i = n - 1; i >= 0; -- i)
                {
                    Console.Write("{0} ", a[i]);
                }
    
    			
    			/*******end********/
    
            }
        }
    }
    

      

  • 相关阅读:
    JAVA文件夹上传解决方案
    PHP文件夹上传解决方案
    JSP文件夹上传解决方案
    Web文件夹上传解决方案
    SpringCloud大文件上传解决方案
    SpringBoot大文件上传解决方案
    SpringMVC大文件上传解决方案
    局域网大文件上传解决方案
    香烟过滤嘴模型
    hdu 1010 Tempter of the Bone 奇偶剪枝
  • 原文地址:https://www.cnblogs.com/mjn1/p/12452159.html
Copyright © 2011-2022 走看看