Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <random>
- using namespace std;
- int main() {
- int n, r;
- cin >> n;
- vector <vector <int> > a;
- vector <int> bolean;
- for (int i = 0; i < n * n; i++) {
- bolean.push_back(i + 1);
- }
- for (int i = 0; i < n; i++) {
- vector <int> b;
- a.push_back(b);
- for (int j = 0; j < n; j++) {
- cin >> r;
- a[i].push_back(r);
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (a[i][j] != 0) {
- bolean[a[i][j] - 1] = 0;
- }
- }
- }
- for (int i = 0; i < bolean.size(); i++) {
- if (bolean[i] == 0) {
- swap(bolean[i], bolean[bolean.size() - 1]);
- bolean.pop_back();
- }
- }
- for (int i = 0; i < bolean.size(); i++) {
- if (bolean[i] == 0) {
- swap(bolean[i], bolean[bolean.size() - 1]);
- bolean.pop_back();
- }
- }
- for (int i = 0; i < bolean.size(); i++) {
- if (bolean[i] == 0) {
- swap(bolean[i], bolean[bolean.size() - 1]);
- bolean.pop_back();
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (a[i][j] == 0) {
- int c = rand() % bolean.size();
- a[i][j] = bolean[c];
- swap(bolean[c], bolean[bolean.size() - 1]);
- bolean.pop_back();
- }
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment