Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- void sort_puzz(int* y, int n) {
- int temp;
- int i, j;
- for (i = 0; i < n - 1; i++) {
- for (j = n - 1; j > i; j--) {
- if (y[j] < y[j - 1]) {
- temp = y[j];
- y[j] = y[j - 1];
- y[j - 1] = temp;
- }
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- int** a = new int* [n];
- for (int i = 0; i < n; i++) {
- a[i] = new int[n];
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cin >> a[i][j];
- }
- }
- int* t = new int[n];
- int c = 1;
- int i = 0;
- int j = n-2;
- int kk = 0;
- while (c <= n-2) {
- int p = j;
- while (j > -1 && i < n-1) {
- t[i] = a[i][j];
- i++; j--;
- kk++;
- }
- sort_puzz(t, kk);
- i = 0;
- j = p;
- while (j >-1 && i < n-1) {
- a[i][j] = t[i];
- i++; j--;
- }
- for (int k = 0; k < kk; k++) {
- t[k] = 0;
- }
- i = 0;
- j= p-1;
- kk = 0;
- c++;
- }
- int u = 0;
- int k = n-1;
- int m = n - 1;
- int g = 0;
- while (u <= n-2) {
- int p = m;
- while (m < n) {
- t[g] = a[k][m];
- k--; m++;
- g++;
- }
- sort_puzz(t, g);
- k = n - 1;
- m = p;
- g = 0;
- while (m < n) {
- a[k][m] = t[g];
- k--; m++;
- g++;
- }
- for (int l = 0; l < g; l++) {
- t[l] = 0;
- }
- g = 0;
- k = n - 1;
- m = p - 1;
- u++;
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement