Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- bool loadFile(std::string fileToOpen);
- int taskOne();
- int taskTwo();
- int taskThree();
- int table[320][200];
- int main() {
- if (!loadFile("dane.txt")) {
- return 0;
- }
- taskOne();
- taskTwo();
- taskThree();
- std::cin.get();
- return 1;
- }
- bool loadFile(std::string fileToOpen) {
- std::fstream openFile(fileToOpen);
- if (!openFile.good())
- return 0;
- for (int y = 0; y < 200; y++) {
- for (int x = 0; x < 320; x++) {
- openFile >> table[x][y];
- }
- }
- openFile.close();
- return 1;
- }
- int taskOne() {
- int maxValue = 0; // Granica dolna dziedziny
- int minValue = 255; // Granica górna dziedziny
- for (int y = 0; y < 200; y++) {
- for (int x = 0; x < 320; x++) {
- if (table[x][y] > maxValue) {
- maxValue = table[x][y];
- }
- if (table[x][y] < minValue) {
- minValue = table[x][y];
- }
- }
- }
- std::cout << "MinValue: " << minValue << std::endl;
- std::cout << "MaxValue: " << maxValue << std::endl;
- return 1;
- }
- int taskTwo() {
- int howManyToErase = 0;
- for (int y = 0; y < 200; y++) {
- for (int x = 0; x < 160; x++) {
- if (table[x][y] != table[319 - x][y]) { // Ostatni element tablicy w rzędzie x ma indeks 319
- howManyToErase++;
- break;
- }
- }
- }
- std::cout << "We need to erase " << howManyToErase << " lines!" << std::endl;
- return 1;
- }
- int taskThree() {
- int howManyPixels = 0;
- for (int y = 0; y < 200; y++) {
- for (int x = 0; x < 320; x++) {
- if ((table[x+1][y] - table[x][y] > 128 || table[x+1][y] - table[x][y] < -128) && x != 319) howManyPixels++;
- else if ((table[x-1][y] - table[x][y] > 128 || table[x-1][y] - table[x][y] < -128) && x != 0) howManyPixels++;
- else if ((table[x][y+1] - table[x][y] > 128 || table[x][y+1] - table[x][y] < -128) && y != 199) howManyPixels++;
- else if ((table[x][y-1] - table[x][y] > 128 || table[x][y-1] - table[x][y] < -128) && y != 0) howManyPixels++;
- }
- }
- std::cout << "There are " << howManyPixels << " specific Pixels!" << std::endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement