Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. // ALG08du.cpp: Definuje vstupní bod pro konzolovou aplikaci.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <random>
  7. #include <fstream>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. const unsigned int N = 10;
  13.  
  14.  
  15. int main()
  16. {
  17.    
  18.     bool matrix[N][N];
  19.  
  20.     random_device rd;
  21.     mt19937 mt(rd());
  22.     uniform_int_distribution<int> dist(0, 1);
  23.    
  24.     for (int i = 0; i < N; i++) {
  25.         for (int j = 0; j < N; j++) {
  26.             matrix[i][j] = dist(mt);
  27.             cout << boolalpha << matrix[i][j] << " ";
  28.         }
  29.         cout << endl;
  30.     }
  31.  
  32.     ofstream f;
  33.     f.open("C:/Users/rnova/source/repos/ALG08du/coord.txt", ios::out);
  34.     if (!f.is_open()) {
  35.         cout << "Whops" << endl;
  36.         return 0;
  37.     }
  38.  
  39.     for (int i = 1; i < N-1; i++) {
  40.         for (int j = 1; j < N-1; j++) {
  41.             if (matrix[i - 1][j] == 1 && matrix[i][j - 1] == 0
  42.                 && ((matrix[i][j + 1] == 0 && matrix[i + 1][j] == 1)
  43.                     || (matrix[i][j + 1] == 1 && matrix[i + 1][j] == 0))) {
  44.                 f << "[" << i << "][" << j << "] ";
  45.             }
  46.         }
  47.     }
  48.     f.close();
  49.     ifstream reader;
  50.     reader.open("C:/Users/rnova/source/repos/ALG08du/coord.txt", ios::in);
  51.     string s;
  52.     getline(reader, s);
  53.     cout << s << endl;
  54.     reader.close();
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement