HDOJ 2019 数列有序!
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
bool cmp(int a, int b) {
return a < b;
}
bool cmp2(int a, int b) {
return a > b;
}
int main() {
int n, m;
&& m != )) {
vector<int> ans;
int t;
while (n--) {
cin >> t;
ans.push_back(t);
}
ans.push_back(m);
] > ans[]) {
sort(ans.begin(), ans.end(), cmp2);
}
else {
sort(ans.begin(), ans.end(), cmp);
}
for (auto it = ans.begin();it != ans.end();it++) {
if (it == ans.begin()) cout << *it;
else cout << " " << *it;
}
cout << endl;
}
;
}
有个坑点,题目中的有序没说是降序还是升序!
HDOJ 2019 数列有序!的更多相关文章
- hdu 2019:数列有序!(数据结构,直接插入排序+折半插入排序)
数列有序! Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- HDU 2019 数列有序!
Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class name ...
- 杭电2019 数列有序!(STL解法)
由于这题对于学过数据结构的我来说,真的是很简单,为了减少时间上的损失,链表无疑是最好的选择(因为数组要往后移位子).然后,因为最近想玩些STL的骚操作,所以就用<list>了,然后顺便学了 ...
- HDOJ2019数列有序!
数列有序! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 新疆大学OJ(ACM) 1099: 数列有序!
1099: 数列有序! 时间限制: 1 Sec 内存限制: 128 MB 题目描述 有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的 ...
- HDU2019数列有序!
Problem Description 有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序. Input 输入数据包含多个测 ...
- 杭电OJ第11页2010-2019道题(C语言)
2010. 水仙花数 问题描述 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个三位 ...
- 杭电oj2012-2021
2012 素数判定 #include <stdio.h> #include <math.h> int main() { int x,y,i,j,a,flag; while(s ...
- 杭电ACM2019--数列有序!
数列有序! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
随机推荐
- 《DSP using MATLAB》Problem5.33
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- ios-UITableView无内容时,不显示多余的分隔线
效果如上. 只要补上以下方法: //设置多于的分割线 -(void)setExtraCellLineHidden: (UITableView *)tableView { UIView *view = ...
- Windows和linux 文件互传
一般我是直接在windows下创建一个共享文件夹,然后在linux挂载,我一直都是这么干的. 直到有一天,我需要往一个公网linux上面传几个文件,可是我的Windows是内网的,所以,这种方法行不通 ...
- System类的使用
1.System类: 不能被实例化,调用方式: System.方法 2.用于计算程序执行的时间,currentTimeMillis()方法 System.currentTimeMillis(): p ...
- C++中的继承和多继承
一.学习笔记 1.继承 class Student : public Person { ... } 2.继承时权限派生类中可以直接访问父类的protected成员,但是不能访问其private成员,若 ...
- go-elasticsearch 来自官方的 golang es client
elasticsearch 终于有了官方的golang sdk 了,地址 https://github.com/elastic/go-elasticsearch 当前还不稳定,同时主要是对于es7 的 ...
- 随机重拍与抽样(random_shuffle,random_sample,random_sample_n)
//版本一:使用内部的随机数生成器 template<class RandomAccessIterator> void random_shuffle( RandomAccessIterat ...
- BinaryReader 自己写序列化
听说过BinaryReader和BinaryWriter吗? 序列化无非就是网络通信时所使用的传输数据的方式,而BinaryWriter可以将数据以二进制的方式写入到流当中.比如Int32型的1用Bi ...
- 解决The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
Spring Boot JPA 使用Mysql是出现如下错误: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represe ...
- 使用php生成数字、字母组合验证码
项目中经常会遇到一些登陆验证,支付验证等等一系列安全验证的策略.实现方法多种多样,下面就来讲解下如何用php生成简单的文字+数字组合的验证码: 所用语言php,gd库 原理解释: a>实质上是在 ...