sort by age(vector)
问题 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)相关推荐
- c++ sort函数排序---vector
c++ sort函数排序–vector 1.头文件#include < algorithm>和using namespace std; 2.它使用的排序方法是类似于快排的方法,时间复杂度为 ...
- std中稳定排序算法_实战c++中的vector系列--使用sort算法对vector进行排序(对vector排序、使用稳定的排序std::stable_sort())...
写了挺多关于vector的操作了,正好工作中遇到对vector进行排序的问题,这里就讨论一下. 直接使用sort算法,那就先了解一下: template void sort (RandomAccess ...
- sort函数用于vector向量的排序
参考资料: 关于C++中vector和set使用sort方法进行排序 作者注:这篇文章写得相当全面,包括对vector和set中不同数据类型(包括结构体)的排序,还有一些还没看懂--特作此摘录,供当前 ...
- C++的sort函数对于vector排序
对于vector<pair<int,int>>类型 // An highlighted block vector<pair<int,int>> v; / ...
- sort()函数排序vector
sort()函数默认的排序方式为升序,如果需要降序排序,可以自定义排序函数 bool comp(int x ,int y) {return x > y; } 对vector 进行排序时 sort ...
- 用sort函数对vector排序
前言 排序一共有两种方法,分别是调用仿函数和函数,这里先调用函数进行升序排序,再调用仿函数进行降序排序. 代码 #include<iostream> #include<vector& ...
- Vector的sort的使用
从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法 sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vec ...
- std list/vector sort 排序就这么简单
网上江湖郎中和蒙古大夫很多,因此,此类帖子也很多.关于排序,我还真没研究过,看了江湖郎中和蒙古大夫的帖子,搞了半天不行,所以,自己研究了一下,如下:三种方式都可以,如重写<,()和写比较函数co ...
- std list/vector sort 自定义类的排序
转载自:http://blog.csdn.net/marising/article/details/4567531 如下:三种方式都可以,如重写<,()和写比较函数compare_index.但 ...
最新文章
- 项目:网站架构,集群
- Linux系统下安装卸载jdk
- C++cycle sort循环排序的实现算法(附完整源码)
- SAP Spartacus里使用Observable访问Component数据
- php mail ld preload,读《利用环境变量LD_PRELOAD来绕过php disable_function执行系统命令》有感...
- loop 伪设备 挂在文件系统
- 信息学奥赛一本通 2024:【例4.10】末两位数
- ARKit:也许是 iPhone 十周年最好的新开始
- 通过两个小栗子来说说Java的sleep、wait、notify、notifyAll的用法
- APP性能测试工具——GT 使用方法
- (SWAT-1)SWAT进行流域提取
- python爬虫新浪微博评论、评论人信息
- html 向上滑动,jQuery - 使用.slideUp()方法向上滑动HTML元素
- 黑盘-蓝盘-绿盘-红盘
- uni-app学习日记7
- 多线程Retry: 解释
- python培训广告语
- 标准化、归一化、中心化
- 设置暴风影音缓存文件夹位置的方法
- 计算机专业的二本大学排名及分数线,全国二本大学排名及分数线