Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- const int N = 20;
- std::vector<std::vector<char>> vector;
- std::vector<char> horizontalLine;
- std::vector<char> verticalLine;
- std::fstream obrazek;
- int czorne = 0;
- int biale = 0;
- bool poprawny = false;
- bool naprawialny = false;
- bool nienaprawialny = false;
- int ileRewers = 0;
- int ileReku = 0;
- int poprawne = 0;
- int naprawialne = 0;
- int niepoprawne = 0;
- int ktory = 0;
- bool recursive()
- {
- bool tak = false;
- if (N % 2 == 0)
- {
- for (int x = 0; x < N / 2; x++)
- {
- for (int y = 0; y < N / 2; y++)
- {
- if (vector[x][y] != vector[N / 2 + x][y] ||
- vector[x][y] != vector[x][y + N / 2] ||
- vector[x][y] != vector[x + N / 2][y + N / 2]) {
- return false;
- tak = false;
- }
- else if (vector[x][y] == vector[N / 2 + x][y] &&
- vector[x][y] == vector[x][y + N / 2] &&
- vector[x][y] == vector[x + N / 2][y + N / 2])
- tak = true;
- }
- }
- if (tak == true) return true;
- }
- else std::cout << "Warunek N niespelniony! "; return false;
- }
- void checkIfCorrect(std::vector<std::vector<char>> vector, std::vector<char> lastLine, std::vector<char> rightLine)
- {
- char bit;
- int pix = 0;
- char check;
- int correctLn = 0;
- int incorrectLn = 0;
- char checkIfCorrectH; //horizontal
- int xLn = 0;
- int yLn = 0;
- int correctColumn = 0;
- int incorrectColumn = 0;
- char checkIfCorrectV; //vertical
- int xClmn = 0;
- int yClmn = 0;
- for (int j = 0; j < N; j++)
- {
- for (int i = 0; i < N; i++)
- {
- if (vector[j][i] == '1') pix++;
- }
- if (pix % 2 == 0) check = '0';
- else check = '1';
- bit = rightLine[j];
- if (bit == check) correctLn++;
- else {
- incorrectLn++;
- xLn = N + 1;
- yLn = j + 1;
- }
- pix = 0;
- }
- if (incorrectLn == 0) checkIfCorrectH = '1'; // poprawny
- else if (incorrectLn == 1) checkIfCorrectH = '2'; // naprawialny
- else checkIfCorrectH = '0'; //nienaprawialny
- pix = 0;
- for (int j = 0; j < N; j++)
- {
- for (int i = 0; i < N; i++)
- {
- if (vector[j][i] == '1') pix++;
- }
- if (pix % 2 == 0) check = '0';
- else check = '1';
- bit = lastLine[j];
- if (bit == check) correctColumn++;
- else { incorrectColumn++; xClmn = j + 1; yClmn = N + 1; }
- pix = 0;
- }
- if (incorrectColumn == 0) checkIfCorrectV = '1';
- else if (incorrectColumn == 1) checkIfCorrectV = '2';
- else checkIfCorrectV = '0';
- if (checkIfCorrectH == '1' && checkIfCorrectV == '1') poprawny = true; //std::cout << "Poprawny";
- else if ((checkIfCorrectH == '2' && checkIfCorrectV == '2')) {
- std::cout << "Naprawialny obrazek " << ktory << std::endl << "Wystarczy zmienić bity parzystości w (" << xLn << "," << yLn << ")" << " i (" << xClmn << "," << yClmn << ")" << std::endl << std::endl; naprawialny = true; }
- 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;
- }
- 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;
- }
- else nienaprawialny = true; //std::cout << "Nienaprawialny";
- }
- bool rewers()
- {
- if (czorne > biale) return true; //std::cout << std::endl << "Rewers" << std::endl << "Czarne piksele: " << czorne;
- return false; //std::cout << "Obraz nie jest rewersem";
- }
- void start()
- {
- obrazek.open("dane_obrazki.txt");
- std::string line;
- vector.resize(20);
- for (int xd = 0; xd <= 200; xd++)
- {
- ktory++;
- for (int y = 0; y < N; y++)
- {
- getline(obrazek, line);
- verticalLine.push_back(line[N]);
- for (int x = 0; x < N; x++)
- {
- vector[x].push_back(line[x]);
- if (line[y] == '1') {
- czorne++;
- }
- if (line[y] == '0') biale++;
- }
- }
- getline(obrazek, line);
- for (int i = 0; i < N; i++)
- {
- horizontalLine.push_back(line[i]);
- }
- if (rewers()) ileRewers++;
- if (recursive()) ileReku++;
- checkIfCorrect(vector, horizontalLine, verticalLine);
- if (poprawny) poprawne++;
- if (naprawialny) naprawialne++;
- if (nienaprawialny) niepoprawne++;
- getline(obrazek, line);
- vector.clear();
- vector.resize(20);
- horizontalLine.clear();
- verticalLine.clear();
- czorne = 0;
- biale = 0;
- poprawny = false;
- naprawialny = false;
- nienaprawialny = false;
- }
- }
- int main()
- {
- setlocale(LC_CTYPE, "Polish");
- start();
- std::cout << std::endl << "Poprawnych obrazów jest: " << poprawne << std::endl;
- std::cout << std::endl << "Naprawialnych obrazów jest: " << naprawialne << std::endl;
- std::cout << std::endl << "Nienaprawialnych obrazów jest: " << niepoprawne << std::endl;
- std::cout << std::endl << "Rewersów jest: " << ileRewers << std::endl;
- std::cout << std::endl << "Rekurencyjnych obrazów jest: " << ileReku << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement