数列有序!
来源:互联网 发布:淘宝手机店铺店招尺寸 编辑:程序博客网 时间:2024/06/05 02:10
Problem Description
有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数m,请将该数插入到序列中,并使新的序列仍然有序。
Input
输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0表示输入数据的结束,本行不做处理。
Output
对于每个测试实例,输出插入新的元素后的数列。
Example Input
3 3
1 2 4
0 0
Example Output
1 2 3 4
#include <iostream>#include <math.h>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[10010];int b[10010];int main(){ int n, m; while(cin>>n>>m && !(n == 0 && m ==0))//n和m不能同时为0 { for(int i = 0; i < n; i++) { cin>>a[i]; } a[n] = m; sort(a, a+n+1);//+1 for(int i = 0; i <= n; i++)//变为n个元素 { if(i == 0) cout<<a[0]; else cout<<" "<<a[i]; } cout<<endl; } return 0;}
阅读全文
0 0
- 数列有序!
- 数列有序
- 数列有序
- 数列有序
- 数列有序
- 数列有序
- 数列有序!
- 数列有序!
- 数列有序
- 数列有序!
- 数列有序
- 数列有序
- 数列有序!
- 数列有序!
- 数列有序!
- 数列有序!
- 数列有序!
- 数列有序!
- gdb attach 进程调试
- VS Code 输出面板中文乱码
- ArchSummit2017干货简介
- c++读取文件时如何读取空格
- hook 应用程序的入口 Activity
- 数列有序!
- leetcode 674[easy]--- Longest Continuous Increasing Subsequence
- LintCode 第407题 加一
- 【爬虫学习】数据绘成图表学习心得
- mysql5.7官网直译数据类型优化--数字,字符串,BLOB等
- 1.1 最大子序列求和
- 编程实现:一个四位数它的数字组合的最大四位数 减去数字组合的最小四位数等于它本身
- HTML5--margin属性的应用
- 支付宝RAS密钥生成器1024位