[] The number of columns and orderly acm2019

*** Title:
Problem the Description
has n (n <= 100) integers, has ascending order good now additionally to an integer x, please insert the number of the sequence, the new sequence and still sequence.

Input
input data comprising a plurality of test cases, each set of data consists of two lines, the first row is n and m, the second line is already ordered n number of columns. n and m are 0 at the same time to mark the end of the input data, without processing the Bank.

Output
For each test case, the number of columns output insert new elements.

Sample Input
3 3
1 2 4
0 0

Sample Output
1 2 3 4***

Code:

#include<iostream>
#include<cstring> 
#include<algorithm>
using namespace std;

int main(){
int n,m,a[100];
while(scanf("%d%d",&n,&m)!=EOF){
	if(m==0&&n==0){
		break;
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	a[0]=m;
	sort(a,a+n+1);
	for(int i=0;i<=n;i++){
		if(i!=n)
		cout<<a[i]<<" ";
		else cout<<a[i]<<endl;
	}
}
	return 0;
}

Analysis: This question directly to the sort method, pay attention to the wording of the header file. Or use a bubble sort or selection can!

Published 42 original articles · won praise 18 · views 400

Guess you like

Origin blog.csdn.net/weixin_42918559/article/details/104042713