问题 B: sort by age

题目描述
You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 101 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.
输入格式
There are multiple test cases in the input file. Each case starts with an integer n (0<n<=2000000), the total number of people. In the next line, there are n integers indicating the ages. Input is terminated with a case where n = 0. This case should not be processed.
输出格式
For each case, print a line with n space separated integers. These integers are the ages of that country sorted in ascending order.
输入样例
5
2 1 4 3 6
3
2 1 3
0
输出样例
1 2 3 4 6
1 2 3
ssn:刚学完八大排序留的作业题,这个数据范围应该是用冒泡会超时,随便用种高级排序就可以。虽然我都没有用,我大概其会用优先队列排完之后在导入一个栈再输出,然后还是学习了点更高级的东西hhhh

#include<bits/stdc++.h>
using namespace std;int main()
{int n;while(cin>>n){if(n==0) break;vector<int> a;for(int i=0;i<n;i++){int x;cin>>x;a.push_back(x);}sort(a.begin(),a.end());vector<int>::iterator it;for(it=a.begin();it!=a.end();it++){cout<<*it<<" ";}cout<<endl;}return 0;
}

sort by age(vector)相关推荐

  1. c++ sort函数排序---vector

    c++ sort函数排序–vector 1.头文件#include < algorithm>和using namespace std; 2.它使用的排序方法是类似于快排的方法,时间复杂度为 ...

  2. std中稳定排序算法_实战c++中的vector系列--使用sort算法对vector进行排序(对vector排序、使用稳定的排序std::stable_sort())...

    写了挺多关于vector的操作了,正好工作中遇到对vector进行排序的问题,这里就讨论一下. 直接使用sort算法,那就先了解一下: template void sort (RandomAccess ...

  3. sort函数用于vector向量的排序

    参考资料: 关于C++中vector和set使用sort方法进行排序 作者注:这篇文章写得相当全面,包括对vector和set中不同数据类型(包括结构体)的排序,还有一些还没看懂--特作此摘录,供当前 ...

  4. C++的sort函数对于vector排序

    对于vector<pair<int,int>>类型 // An highlighted block vector<pair<int,int>> v; / ...

  5. sort()函数排序vector

    sort()函数默认的排序方式为升序,如果需要降序排序,可以自定义排序函数 bool comp(int x ,int y) {return x > y; } 对vector 进行排序时 sort ...

  6. 用sort函数对vector排序

    前言 排序一共有两种方法,分别是调用仿函数和函数,这里先调用函数进行升序排序,再调用仿函数进行降序排序. 代码 #include<iostream> #include<vector& ...

  7. Vector的sort的使用

    从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法 sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vec ...

  8. std list/vector sort 排序就这么简单

    网上江湖郎中和蒙古大夫很多,因此,此类帖子也很多.关于排序,我还真没研究过,看了江湖郎中和蒙古大夫的帖子,搞了半天不行,所以,自己研究了一下,如下:三种方式都可以,如重写<,()和写比较函数co ...

  9. std list/vector sort 自定义类的排序

    转载自:http://blog.csdn.net/marising/article/details/4567531 如下:三种方式都可以,如重写<,()和写比较函数compare_index.但 ...

最新文章

  1. 项目:网站架构,集群
  2. Linux系统下安装卸载jdk
  3. C++cycle sort循环排序的实现算法(附完整源码)
  4. SAP Spartacus里使用Observable访问Component数据
  5. php mail ld preload,读《利用环境变量LD_PRELOAD来绕过php disable_function执行系统命令》有感...
  6. loop 伪设备 挂在文件系统
  7. 信息学奥赛一本通 2024:【例4.10】末两位数
  8. ARKit:也许是 iPhone 十周年最好的新开始
  9. 通过两个小栗子来说说Java的sleep、wait、notify、notifyAll的用法
  10. APP性能测试工具——GT 使用方法
  11. (SWAT-1)SWAT进行流域提取
  12. python爬虫新浪微博评论、评论人信息
  13. html 向上滑动,jQuery - 使用.slideUp()方法向上滑动HTML元素
  14. 黑盘-蓝盘-绿盘-红盘
  15. uni-app学习日记7
  16. 多线程Retry: 解释
  17. python培训广告语
  18. 标准化、归一化、中心化
  19. 设置暴风影音缓存文件夹位置的方法
  20. 计算机专业的二本大学排名及分数线,全国二本大学排名及分数线

热门文章

  1. 协方差矩阵的几何解释
  2. Java8--20道关于Stream流的题目练习
  3. H5 可视化构建工具原理解析(一)
  4. Google Voice、Voice Search 安装
  5. Bugzilla使用说明
  6. ubuntu搜狗输入法中文无法切换英文
  7. 2012 SDCC中国软件开发者大会门票社区团购火热开启!
  8. python文件管理器_Tkinter 之文件管理器
  9. 数据链路层 随机接入-CSMA/CA协议
  10. eNSP配置静态路由及默认路由的三种案例