#include <iostream>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
int a[n][m], res[n*m], cur = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
res[cur] = a[i][j];
cur++;
}
for(int i = 0; i < n*m; i++){
for(int j = i + 1; j < n*m; j++){
if(res[i] > res[j])
swap(res[i],res[j]);
cur = 0;
cout << res[cur] << " ";
cout << "\n";
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
int a[n][m], res[n*m], cur = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
res[cur] = a[i][j];
cur++;
}
}
for(int i = 0; i < n*m; i++){
for(int j = i + 1; j < n*m; j++){
if(res[i] > res[j])
swap(res[i],res[j]);
}
}
cur = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << res[cur] << " ";
cur++;
}
cout << "\n";
}
}