zoukankan      html  css  js  c++  java
  • 华科机考:特殊排序

    时间限制:1秒     空间限制:32768K

    题目描述:

    输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序。

    输入描述: 输入第一行包括1个整数N,1<=N<=1000,代表输入数据的个数。 接下来的一行有N个整数。

    输出描述: 可能有多组测试数据,对于每组数据, 第一行输出一个整数,代表N个整数中的最大值,并将此值从数组中去除,将剩下的数进行排序。 第二行将排序的结果输出。

    输入例子: 4

                 1 3 4 2

    输出例子: 4

                 1 2 3

    这里要吐槽一下,只有一个数的时候需要输出-1诶,毕竟是2003年机试题,也别要求那么高

    代码:

    #include <iostream>
    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    
    
    int main(){
      int n;
      int a[1010];
      while(cin>>n){
      for(int i=0;i<n;i++)
       cin>>a[i];
      sort(a,a+n);
      cout<<a[n-1]<<endl;
      if(n>1){
      for(int i=0;i<n-1;i++){
         if(i==0)
         cout<<a[i];
         else
         cout<<" "<<a[i];
      }
      cout<<endl;
      }
      else
      cout<<-1<<endl;
      }
      return 0;
    }
  • 相关阅读:
    组播IP地址
    改变未来的10大科技
    知行合一之健康
    2017第47周五
    2017第47周四感恩节
    spring boot测试
    2017第47周二
    音频格式opus
    周日反思
    四种人工智能技术对五个行业的影响
  • 原文地址:https://www.cnblogs.com/mlgjb/p/6659651.html
Copyright © 2011-2022 走看看