Advertisement
Guest User

3

a guest
Apr 4th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.    
  9.  
  10.     ifstream dane("dane_obrazki.txt");
  11.     if (!dane.is_open()) {
  12.         return -1;
  13.     }
  14.    
  15.     int good = 0, fixable = 0, completlyDestroied = 0;
  16.     for (int obrazIndex = 0; obrazIndex < 200; obrazIndex++) {
  17.        
  18.         bool obraz[20][20];
  19.         int xErrors = 0, yErrors = 0;
  20.         for (int y = 0; y < 20; y++) {
  21.             int ones = 0;
  22.             string row = "";
  23.             if (!(dane >> row)) {
  24.                 return -2;
  25.             }
  26.            
  27.             for (int x = 0; x < 20; x++) {
  28.                 obraz[y][x] = row[x] - '0';
  29.                
  30.                 if (obraz[y][x]) ones++;
  31.                
  32.                 if (x == 19) {
  33.                     // Bit parzysto?ci
  34.                     bool b = row[20] - '0';
  35.                     if ((ones%2==0) && b) {
  36.                         xErrors++;
  37.                     }
  38.                     //cout << row << endl << endl;
  39.                     //cout << endl << "ones: "<< ones  << " b: " << row[20] << endl;
  40.                 }
  41.             }
  42.            
  43.             if (y == 19) {
  44.                 // Bity parzysto?ci kolumn
  45.                 if (!(dane >> row)) {
  46.                     return -3;
  47.                 }
  48.                
  49.                 //cout << row << endl << endl;
  50.                
  51.                 string s = row;
  52.                 for (int j = 2; j < s.length(); j++) {
  53.                     bool b = s[j] - '0';
  54.                     int c1 = 0;
  55.                    
  56.                     for (int i = 0; i < 20; i++) {
  57.                         //cout << obraz[i][j] << endl;
  58.                         if (obraz[i][j]) c1++;
  59.                     }
  60.                    
  61.                     if ((c1%2==0) && b) {
  62.                         yErrors++;
  63.                     }
  64.                     //cout << endl << c1 << " " << b << endl;
  65.                     //break;
  66.                 }
  67.             }
  68.         }
  69.        
  70.         if ((xErrors > 1)&&(yErrors > 1)) completlyDestroied++;
  71.         else if ((xErrors <= 1)&&(yErrors <= 1)) fixable++;
  72.         else good++;
  73.         //break;
  74.     }
  75.    
  76.     cout << good << endl;
  77.     cout << fixable << endl;
  78.     cout << completlyDestroied << endl;
  79.    
  80.     dane.close();
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement