九度OJ 1185:特殊排序 (排序)
来源:互联网 发布:白话数据库三大范式 编辑:程序博客网 时间:2024/05/24 06:30
- 题目描述:
输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序。
- 输入:
- 输入第一行包括1个整数N,1<=N<=1000,代表输入数据的个数。接下来的一行有N个整数。
- 输出:
- 可能有多组测试数据,对于每组数据,第一行输出一个整数,代表N个整数中的最大值,并将此值从数组中去除,将剩下的数进行排序。第二行将排序的结果输出。
- 样例输入:
41 3 4 2
- 样例输出:
41 2 3
- 提示:
如果数组中只有一个数,当第一行将其输出后,第二行请输出"-1"。
- 来源:
- 2003-2005年华中科技大学计算机研究生机试真题
思路:
先排序再取出最大值。
代码:
#include <stdio.h>#include <string.h>#include <stdlib.h> #define N 1000 int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;} int main(void){ int n; int i; int a[N]; while (scanf("%d", &n) != EOF) { for (i=0; i<n; i++) scanf("%d", &a[i]); qsort(a, n, sizeof(a[0]), cmp); printf("%d\n", a[n-1]); if (n == 1) printf("-1\n"); else { for (i=0; i<n-2; i++) printf("%d ", a[i]); printf("%d\n", a[i]); } } return 0;}/************************************************************** Problem: 1185 User: liangrx06 Language: C Result: Accepted Time:30 ms Memory:912 kb****************************************************************/
0 0
- 九度OJ 1185:特殊排序 (排序)
- 九度OJ 1185 特殊排序
- 九度oj-1185-特殊排序
- 九度OJ题目1185:特殊排序
- 九度oj 题目1185:特殊排序
- 九度OJ-1185:特殊排序
- 题目1185:特殊排序 九度OJ
- 【九度OJ】1185:特殊排序
- 【九度OJ】题目1185:特殊排序 解题报告
- 【九度OJ】题目1185:特殊排序 解题报告
- OJ 1185 特殊排序
- 九度OJ 1202:排序 (排序)
- 【九度】题目1185:特殊排序
- 九度题目1185:特殊排序
- 九度 题目1185:特殊排序
- 九度-题目1185--特殊排序
- 【九度】题目1185:特殊排序
- 九度OJ 1014:排名 (排序)
- struts.xml常量配置
- java List与json的转换
- [Android] Handler源码解析 (Native层)
- C++中的容器类详解
- CB-9685 A fix for the magnifying glass popping up on iOS9 when longpr
- 九度OJ 1185:特殊排序 (排序)
- iOS UIPopoverController的使用
- 基于node.js的web程序入门
- 【数据库】Join连接
- 把时间戳转换为几秒前 几天前
- Storm——Topoloty部署
- FileZilla中文乱码解决方法
- R语言一路屏障
- 工具推荐 - windows下iOS设备越狱的