Nagy_Szabolcs

graf 2

Sep 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void beolvasas(int pp_mat[][50], int& n) {
  7.     ifstream fin("boole.txt");
  8.     fin >> n;
  9.    
  10.     int i, j;
  11.     for (i = 0; i < n; i++) {
  12.         for (j = 0; j < n; j++)
  13.             fin >> pp_mat[i][j];
  14.     }
  15. }
  16.  
  17. void pp_mat_ki(int pp_mat[][50], int n) {
  18.     int i, j;
  19.  
  20.     for (i = 0; i < n; i++) {
  21.         for (j = 0; j < n; j++)
  22.             cout << pp_mat[i][j] << ' ';
  23.         cout << endl;
  24.     }
  25. }
  26.  
  27. void ell_mat_tolt(int pp_mat[][50], int ell_mat[][2], int n) {
  28.     int i, j, ell_index = 0;
  29.  
  30.     for (int i = 0; i < n; i++) {
  31.         for (int j = 0; j < n; j++) {
  32.            
  33.             if (pp_mat[i][j]) {
  34.                 ell_mat[ell_index][0] = i+1;
  35.                 ell_mat[ell_index][1] = j+1;
  36.  
  37.                 ell_index++;
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. int el_szamitas(int pp_mat[][50], int n) {
  44.     int m = 0;
  45.  
  46.     for (int i = 0; i < n; i++) {
  47.         for (int j = 0; j < n; j++) {
  48.  
  49.             if (pp_mat[i][j]) {
  50.                 m++;
  51.             }
  52.         }
  53.     }
  54.  
  55.     return m;
  56. }
  57.  
  58. void ell_mat_ki(int ell_mat[][2], int m) {
  59.  
  60.     for (int i = 0; i < m; i++) {
  61.         cout << ell_mat[i][0] << ' ' << ell_mat[i][1] << endl;
  62.     }
  63. }
  64. int main()
  65. {
  66.     int pp_mat[50][50], n;
  67.     beolvasas(pp_mat, n);
  68.     pp_mat_ki(pp_mat, n);
  69.  
  70.     cout << endl << endl;
  71.     int ell_mat[50][2],m;
  72.     m = el_szamitas(pp_mat, n);
  73.     ell_mat_tolt(pp_mat, ell_mat, n);
  74.     ell_mat_ki(ell_mat, m);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment