c_code

no des
 avatar
mhuyy2k3
c_cpp
2 years ago
748 B
4
Indexable
Never
#include <iostream>
#define MAX 100

using namespace std;

int main(){
	int n, m, max, nTests;
	
	cin >> nTests;
	
	for(int nTest = 0; nTest < nTests; nTest++){
		cin >> n >> m;
		int arr[n];
	
		for(int i=0; i<n; i++){
			cin>>arr[i];
		}
		// Tim kiem max;
		max = arr[0];
		
		for(int i=0; i<n; i++){
			if(max<arr[i]){
				max=arr[i];
			}
		}
		
		// In so am truoc
		for(int i=0;i<n;i++){
			if(max == arr[i] && arr[i] < 0){
				cout<< max << " ";
			}
			if(arr[i]<0){
				cout << arr[i] << " ";
			}
		}
		// In so duong sau
		for(int i=0;i<n;i++){
			if(max == arr[i] && arr[i] > 0){
				cout<< m << " ";
			}
			if(arr[i]>=0){
				cout << arr[i] << " ";
			}
		}
		cout << endl;
	}
	
	
	
}