Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<int> wszystkieLiczby;
- int floodFill(vector<vector<char>> &arr, short xCoord, short yCoord, char targetColor, short replacementColor,int &iloscPrzejsc,int xMax,int yMax) {
- if (xCoord >=arr.size() || xCoord < 0 || yCoord >=arr[0].size() || yCoord < 0) return -1;// naprawić ten warunek
- if (targetColor == replacementColor) return -1;
- if (arr[xCoord][yCoord] != replacementColor) return -1;
- arr[xCoord][yCoord] = targetColor;
- iloscPrzejsc++;
- floodFill(arr, xCoord + 1, yCoord, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
- floodFill(arr, xCoord - 1, yCoord, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
- floodFill(arr, xCoord, yCoord + 1, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
- floodFill(arr, xCoord, yCoord - 1, targetColor, replacementColor,iloscPrzejsc,xMax,yMax);
- return iloscPrzejsc;
- }
- void printSquareArr(vector<vector<char>> arr) {
- for (int i = 0; i < arr[0].size(); i++) {
- for (int q = 0; q < arr.size(); q++) {
- cout << arr[q][i] << ' ';
- }
- cout << '\n';
- }
- }
- int main() {
- int dlugoscX,dlugoscY;
- char x;
- cin>>dlugoscY>>dlugoscX;
- vector<vector<char>> testArr ;
- for(int i=0;i<dlugoscX;i++)
- {
- vector<char> zmienna;
- for(int j=0;j<dlugoscY;j++)
- {
- zmienna.push_back('z');
- }
- testArr.push_back(zmienna);
- }
- for(int i=0;i<dlugoscX;i++)
- {
- for(int j=0;j<dlugoscY;j++)
- {
- cin>>x;
- testArr[i][j]=x;
- }
- }
- // printSquareArr(testArr);
- string userInput;
- // printSquareArr(testArr);
- short xCoord, yCoord;
- char targetColor='S';
- // cout << "Filling Array...\n";
- char replacementColor = 'x';
- for (int yIndex = 0; yIndex < testArr[0].size(); yIndex++) {
- for (int xIndex = 0; xIndex < testArr.size(); xIndex++) {
- if(testArr[xIndex][yIndex]==replacementColor)
- {
- int iloscPrzejsc=0;
- wszystkieLiczby.push_back(floodFill(testArr, xIndex, yIndex, targetColor, replacementColor,iloscPrzejsc,dlugoscX-1,dlugoscY-1));
- }
- }
- }
- // printSquareArr(testArr);
- sort(wszystkieLiczby.begin(),wszystkieLiczby.end());
- cout<<wszystkieLiczby[wszystkieLiczby.size()-1]<<" "<<wszystkieLiczby[0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement