Created
January 10, 2019 14:35
-
-
Save theotheo/594d8ebdaf4fa75495e057b7838bdcd4 to your computer and use it in GitHub Desktop.
Reorder matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() | |
{ | |
int n = 5; | |
int aa[5][5]; | |
int a[5][5] = { | |
{0, 1, 1, 1, 1}, | |
{1, 1, 0, 1, 1}, | |
{1, 0, 1, 1, 1}, | |
{1, 1, 1, 0, 1}, | |
{1, 1, 1, 1, 0}}; | |
for(int i=0; i < n; i++) { | |
int pos = std::distance(a[i], std::find(a[i], a[i] + n, 0)); | |
std::copy(a[i], a[i] + n, aa[n - 1 - pos]); | |
} | |
std::cout << "original"; | |
for(int i=0; i < n; i++) { | |
for(int j=0; j < n; j++) { | |
std::cout << a[i][j]; | |
} | |
std::cout << std::endl; | |
} | |
std::cout << "sorted"; | |
for(int i=0; i < n; i++) { | |
for(int j=0; j < n; j++) { | |
std::cout << aa[i][j]; | |
} | |
std::cout << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment