Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int riadky = 5;
- int casty = 5;
- cin >> riadky;
- cin >> casty;
- string ostrov[riadky];
- for(int i = 0; i < riadky; i++)
- {
- cin >> ostrov[i];
- }
- int pocetOstrovou = 0;
- int** infoPolicko = new int*[riadky];
- for(int i = 0; i < riadky; ++i)
- {
- infoPolicko[i] = new int[casty];
- for(int j = 0; j < casty; j++)
- {
- infoPolicko[i][j] = -1;
- }
- }
- for(int x = 0; x < riadky; x++)
- {
- for(int y = 0; y < casty; y++)
- {
- if(ostrov[x][y] == '#')
- {
- int create = -1;
- if(x != 0 && ostrov[x - 1][y] == '#')
- {
- create = infoPolicko[x - 1][y];
- }
- if(y != 0 && ostrov[x][y - 1] == '#')
- {
- create = infoPolicko[x][y - 1];
- }
- if(create == -1)
- {
- pocetOstrovou++;
- create = pocetOstrovou;
- }
- infoPolicko[x][y] = create;
- }
- }
- }
- cout << pocetOstrovou << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement