YorKnEz

Problema 14

Dec 4th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[50][50], n, m;
  6.  
  7. void Citeste() {
  8. cin >> n >> m;
  9.  
  10. for (int i = 0; i < n; i++) {
  11. for (int j = 0; j < m; j++) {
  12. cin >> a[i][j];
  13. }
  14. }
  15. }
  16.  
  17. void InterC(int x, int y) {
  18. for (int i = 0; i < n; i++) {
  19. swap(a[i][x], a[i][y]);
  20. }
  21. }
  22.  
  23. void Sortare() {
  24. for (int i = 0; i < n-1; i++) {
  25. for (int j = i+1; j < m; j++) {
  26. if (a[n-1][i] % 2 == 0 && a[n-1][j] % 2 == 0 && a[n-1][i] > a[n-1][j]) {
  27. InterC(i, j);
  28. }
  29. }
  30. }
  31. }
  32.  
  33. void Scrie() {
  34. for (int i = 0; i < n; i++) {
  35. for (int j = 0; j < m; j++) {
  36. cout << a[i][j] << ' ';
  37. }
  38. cout << '\n';
  39. }
  40. }
  41.  
  42. int main() {
  43. Citeste();
  44.  
  45. Sortare();
  46.  
  47. Scrie();
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment