Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. const int N = 20;
  7. std::vector<std::vector<char>> vector;
  8. std::vector<char> horizontalLine;
  9. std::vector<char> verticalLine;
  10. std::fstream obrazek;
  11. int czorne = 0;
  12. int biale = 0;
  13. bool poprawny = false;
  14. bool naprawialny = false;
  15. bool nienaprawialny = false;
  16. int ileRewers = 0;
  17. int ileReku = 0;
  18. int poprawne = 0;
  19. int naprawialne = 0;
  20. int niepoprawne = 0;
  21. int ktory = 0;
  22.  
  23. bool recursive()
  24. {
  25.     bool tak = false;
  26.     if (N % 2 == 0)
  27.     {
  28.         for (int x = 0; x < N / 2; x++)
  29.         {
  30.             for (int y = 0; y < N / 2; y++)
  31.             {
  32.                 if (vector[x][y] != vector[N / 2 + x][y] ||
  33.                     vector[x][y] != vector[x][y + N / 2] ||
  34.                     vector[x][y] != vector[x + N / 2][y + N / 2]) {
  35.                     return false;
  36.                     tak = false;
  37.                 }
  38.                 else if (vector[x][y] == vector[N / 2 + x][y] &&
  39.                     vector[x][y] == vector[x][y + N / 2] &&
  40.                     vector[x][y] == vector[x + N / 2][y + N / 2])
  41.                     tak = true;
  42.             }
  43.         }
  44.         if (tak == true) return true;
  45.     }
  46.     else std::cout << "Warunek N niespelniony! "; return false;
  47. }
  48.  
  49. void checkIfCorrect(std::vector<std::vector<char>> vector, std::vector<char> lastLine, std::vector<char> rightLine)
  50. {
  51.     char bit;
  52.     int pix = 0;
  53.     char check;
  54.  
  55.     int correctLn = 0;
  56.     int incorrectLn = 0;
  57.     char checkIfCorrectH; //horizontal
  58.     int xLn = 0;
  59.     int yLn = 0;
  60.  
  61.     int correctColumn = 0;
  62.     int incorrectColumn = 0;
  63.     char checkIfCorrectV; //vertical
  64.     int xClmn = 0;
  65.     int yClmn = 0;
  66.  
  67.     for (int j = 0; j < N; j++)
  68.     {
  69.         for (int i = 0; i < N; i++)
  70.         {
  71.             if (vector[j][i] == '1') pix++;
  72.         }
  73.         if (pix % 2 == 0) check = '0';
  74.         else check = '1';
  75.         bit = rightLine[j];
  76.         if (bit == check) correctLn++;
  77.         else {
  78.             incorrectLn++;
  79.             xLn = N + 1;
  80.             yLn = j + 1;
  81.         }
  82.         pix = 0;
  83.     }
  84.     if (incorrectLn == 0) checkIfCorrectH = '1'; // poprawny
  85.     else if (incorrectLn == 1) checkIfCorrectH = '2'; // naprawialny
  86.     else checkIfCorrectH = '0'; //nienaprawialny
  87.     pix = 0;
  88.  
  89.     for (int j = 0; j < N; j++)
  90.     {
  91.         for (int i = 0; i < N; i++)
  92.         {
  93.             if (vector[j][i] == '1') pix++;
  94.         }
  95.         if (pix % 2 == 0) check = '0';
  96.         else check = '1';
  97.         bit = lastLine[j];
  98.         if (bit == check) correctColumn++;
  99.         else { incorrectColumn++; xClmn = j + 1; yClmn = N + 1; }
  100.         pix = 0;
  101.     }
  102.     if (incorrectColumn == 0) checkIfCorrectV = '1';
  103.     else if (incorrectColumn == 1) checkIfCorrectV = '2';
  104.     else checkIfCorrectV = '0';
  105.  
  106.     if (checkIfCorrectH == '1' && checkIfCorrectV == '1') poprawny = true; //std::cout << "Poprawny";
  107.     else if ((checkIfCorrectH == '2' && checkIfCorrectV == '2')) {
  108.         std::cout << "Naprawialny obrazek " << ktory << std::endl << "Wystarczy zmienić bity parzystości w (" << xLn << "," << yLn << ")" << " i (" << xClmn << "," << yClmn << ")" << std::endl << std::endl; naprawialny = true; }
  109.     else if ((checkIfCorrectH == '1' && checkIfCorrectV == '2')) {std::cout << "Naprawialny obrazek " << ktory << std::endl << "Wystarczy zmienić bit parzystości w (" << xClmn << "," << yClmn << ")" << std::endl << std::endl; naprawialny = true;
  110.     }
  111.     else if ((checkIfCorrectH == '2' && checkIfCorrectV == '1')) {std::cout << "Naprawialny obrazek " << ktory << std::endl << "Wystarczy zmienic bit parzystości w (" << xLn << "," << yLn << ")" << std::endl << std::endl; naprawialny = true;
  112.     }
  113.     else nienaprawialny = true; //std::cout << "Nienaprawialny";
  114.  
  115. }
  116.  
  117. bool rewers()
  118. {
  119.     if (czorne > biale) return true; //std::cout << std::endl << "Rewers" << std::endl << "Czarne piksele: " << czorne;
  120.     return false; //std::cout << "Obraz nie jest rewersem";
  121. }
  122.  
  123. void start()
  124. {
  125.     obrazek.open("dane_obrazki.txt");
  126.     std::string line;
  127.     vector.resize(20);
  128.  
  129.     for (int xd = 0; xd <= 200; xd++)
  130.     {
  131.         ktory++;
  132.         for (int y = 0; y < N; y++)
  133.         {
  134.             getline(obrazek, line);
  135.             verticalLine.push_back(line[N]);
  136.             for (int x = 0; x < N; x++)
  137.             {
  138.                 vector[x].push_back(line[x]);
  139.  
  140.  
  141.                 if (line[y] == '1') {
  142.                     czorne++;
  143.                 }
  144.                 if (line[y] == '0') biale++;
  145.             }
  146.         }
  147.         getline(obrazek, line);
  148.         for (int i = 0; i < N; i++)
  149.         {
  150.             horizontalLine.push_back(line[i]);
  151.         }
  152.  
  153.         if (rewers()) ileRewers++;
  154.         if (recursive()) ileReku++;
  155.         checkIfCorrect(vector, horizontalLine, verticalLine);
  156.         if (poprawny) poprawne++;
  157.         if (naprawialny) naprawialne++;
  158.         if (nienaprawialny) niepoprawne++;
  159.  
  160.         getline(obrazek, line);
  161.         vector.clear();
  162.         vector.resize(20);
  163.         horizontalLine.clear();
  164.         verticalLine.clear();
  165.         czorne = 0;
  166.         biale = 0;
  167.         poprawny = false;
  168.         naprawialny = false;
  169.         nienaprawialny = false;
  170.     }
  171. }
  172.  
  173. int main()
  174. {
  175.    setlocale(LC_CTYPE, "Polish");
  176.    start();
  177.    std::cout << std::endl << "Poprawnych obrazów jest: " << poprawne << std::endl;
  178.    std::cout << std::endl << "Naprawialnych obrazów jest: " << naprawialne << std::endl;
  179.    std::cout << std::endl << "Nienaprawialnych obrazów jest: " << niepoprawne << std::endl;
  180.    std::cout << std::endl << "Rewersów jest: " << ileRewers << std::endl;
  181.    std::cout << std::endl << "Rekurencyjnych obrazów jest: " << ileReku << std::endl;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement