Advertisement
Guest User

Costa

a guest
Sep 20th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. char mapa[1000][1000];
  6.  
  7. int main(){
  8.  
  9. int m, n, costa = 0;
  10.  
  11. cin >> m >> n;
  12.  
  13. for(int i = 0; i < m; i++){ // linha
  14. for(int j = 0; j < n; j++){ // coluna
  15. cin >> mapa[i][j];
  16. }
  17. }
  18.  
  19. for(int i = 0; i < m; i++){ // linha
  20. for(int j = 0; j < n; j++){ // coluna
  21.  
  22. if(i == 0 || j == 0 || i == (m-1) || j == (n-1) ){ // se for as extremidades analiso aqui
  23.  
  24. if(mapa[i][j] == '#'){
  25. costa++;
  26. }
  27.  
  28. }else{ // senao for, analiso aq
  29.  
  30. if(mapa[i][j] == '#'){
  31.  
  32. if(mapa[i][j-1] == '.' || mapa[i][j+1] == '.' || mapa[i-1][j] == '.' || mapa[i+1][j] == '.'){
  33. costa++;
  34. }
  35. }
  36.  
  37. }
  38.  
  39. }
  40. }
  41.  
  42. cout << costa << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement