小陈的开学第十三周代码

一、第二届中国计量大学ACM程序设计竞赛个人赛(同步赛)

1.Little Gyro and Sort

题意

Little Gyro has just found an integer sequence a1,a2,…,an in his right pocket. As Little Gyro is bored, he decides to sort the sequence.
Now given an integer sequence, and its size is no more than 10^6, please sort it within the ascending order.

输入

There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:The first line contains an integer n (1 ≤ n ≤ 10^6 ), indicating the length of the sequence.
The second line contains n integers a1,a2,…,an (1 ≤ ai≤ 10^4), indicating the given sequence.

输出

For each test case output the sequence after sorting.
Note: Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!

样例输入

2
5
1 4 8 3 7
6
10000 9999 9998 9997 9996 9995

样例输出

1 3 4 7 8
9995 9996 9997 9998 9999 10000

解题思路

刚开始用的sort,超时了;用了冒泡和选择排序,都超时了;后来用了桶排序,结果过了。果然不能想太多。

程序代码

#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int a[N+5];
int main(){
   
	int T;
	scanf("%d",&T);
	while(T--){
   
		memset(a,0,sizeof(a));
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
   
			int temp;
			scanf("%d",&temp);
			a[temp]++;
		}
		int cnt=0;
		
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值