Advertisement
adwas33

Untitled

Jan 22nd, 2022
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. vector<int> wszystkieLiczby;
  7.  
  8. int  floodFill(vector<vector<char>> &arr, short xCoord, short yCoord, char targetColor, short replacementColor,int &iloscPrzejsc,int xMax,int yMax) {
  9.  
  10.     if (xCoord >=arr.size()  || xCoord < 0 || yCoord >=arr[0].size()  || yCoord < 0) return -1;// naprawić ten warunek
  11.  
  12.     if (targetColor == replacementColor) return -1;
  13.  
  14.     if (arr[xCoord][yCoord] != replacementColor) return -1;
  15.  
  16.     arr[xCoord][yCoord] = targetColor;
  17.     iloscPrzejsc++;
  18.  
  19.     floodFill(arr, xCoord + 1, yCoord, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
  20.     floodFill(arr, xCoord - 1, yCoord, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
  21.     floodFill(arr, xCoord, yCoord + 1, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
  22.     floodFill(arr, xCoord, yCoord - 1, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
  23.  
  24.     return iloscPrzejsc;
  25.  
  26. }
  27.  
  28.  
  29.  
  30. void printSquareArr(vector<vector<char>> arr) {
  31.     for (int i = 0; i < arr[0].size(); i++) {
  32.         for (int q = 0; q < arr.size(); q++) {
  33.             cout << arr[q][i] << ' ';
  34.         }
  35.         cout << '\n';
  36.     }
  37. }
  38.  
  39.  
  40.  
  41. int main() {
  42.  
  43.  
  44.  
  45.  
  46.     int dlugoscX,dlugoscY;
  47.     char x;
  48.     cin>>dlugoscY>>dlugoscX;
  49.  
  50.  
  51.  
  52.     vector<vector<char>> testArr ;
  53.  
  54.  
  55.     for(int i=0;i<dlugoscX;i++)
  56.     {
  57.         vector<char> zmienna;
  58.         for(int j=0;j<dlugoscY;j++)
  59.         {
  60.  
  61.             zmienna.push_back('z');
  62.         }
  63.         testArr.push_back(zmienna);
  64.     }
  65.     for(int i=0;i<dlugoscX;i++)
  66.     {
  67.         for(int j=0;j<dlugoscY;j++)
  68.         {
  69.             cin>>x;
  70.             testArr[i][j]=x;
  71.         }
  72.     }
  73.  
  74. //    printSquareArr(testArr);
  75.  
  76.     string userInput;
  77.  
  78.  
  79.  
  80.  
  81.  
  82. //        printSquareArr(testArr);
  83.  
  84.         short xCoord, yCoord;
  85.         char targetColor='S';
  86.  
  87.  
  88.  
  89. //        cout << "Filling Array...\n";
  90.  
  91.         char replacementColor = 'x';
  92.  
  93.     for (int yIndex = 0; yIndex < testArr[0].size(); yIndex++) {
  94.         for (int xIndex = 0; xIndex < testArr.size(); xIndex++) {
  95.             if(testArr[xIndex][yIndex]==replacementColor)
  96.             {
  97.                 int iloscPrzejsc=0;
  98.                 wszystkieLiczby.push_back(floodFill(testArr, xIndex, yIndex, targetColor, replacementColor,iloscPrzejsc,dlugoscX-1,dlugoscY-1));
  99.  
  100.             }
  101.         }
  102.     }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. //        printSquareArr(testArr);
  110.  
  111.  
  112.     sort(wszystkieLiczby.begin(),wszystkieLiczby.end());
  113.  
  114. cout<<wszystkieLiczby[wszystkieLiczby.size()-1]<<" "<<wszystkieLiczby[0];
  115.  
  116.     return 0;
  117. }
  118.  
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement