【NYOJ】[255]C小加 之 随机数
2016-02-21 04:05
288 查看
去重后进行排序
写的时候用了sort
然后排序后去重
[code]#include<stdio.h> #include<algorithm> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { int a[120]; int b[120]; int n; scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d",&a[i]); sort(a,a+n); b[0]=a[0]; int cnt=1; for(int i=1; i<n; i++) { if(a[i]!=a[i-1]) { b[cnt++]=a[i]; } } printf("%d\n",cnt); for(int i=0; i<cnt; i++) { printf("%d",b[i]); if(i==cnt-1) printf("\n"); else printf(" "); } } return 0; }
题目地址:【NYOJ】[255]C小加 之 随机数
相关文章推荐
- 【杭电】[2042]不容易系列之二
- python有超时的windows系统时间设置代码
- 【杭电】[2071]Max Num
- Android自定义Toast总结(下)
- LeetCode Closest Binary Search Tree Value II
- 有关unrecognized selector sent to instance xxxxxxxxx的异常崩溃
- 【DP】scu4441
- Pointers
- 程序员的认识
- MyQL修改用户名命令、密码
- [LeetCode328] Odd Even Linked List
- hadoop入门学习
- 【Nginx入门系列】第二章 外部无法访问Nginx服务器
- Codeforces 629B Far Relative’s Problem(简单区间贪心)
- Codeforces Round #343 (Div. 2) 629D. Babaei and Birthday Cake 线段树
- 对linux源码中thread_info的一点说明
- 关于linker command failed with exit code 1 (use -v to see invocation)错误
- OC基础 - 01类与对象
- 使用Qt Creator编译cpp遇到错误cc1plus.exe: out of memory allocating
- 【Nginx入门系列】第一章 手把手带你搭建Nginx服务器