Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /******EJERCICIO 6_B*****/
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. int Cumple(int alto, int ancho, char **matriz);
  6.  
  7. int main(){
  8. int celda=0;
  9. int ancho,alto;
  10. char M[100][100];
  11.  
  12. while(1){
  13. scanf("%d %d",&ancho,&alto);
  14. if((!alto)||(!ancho))
  15. break;
  16.  
  17. for(int i=0; i<=alto; i++)
  18. for(int j=0; j<=ancho; j++)
  19. scanf("%c",&M[i][j]);
  20.  
  21. celda = Cumple(alto, ancho, M);
  22.  
  23. printf("%d",celda);
  24.  
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30. int Cumple(int alto, int ancho, char **matriz){
  31. int cont = 0, celda= 0;
  32.  
  33. for(int i=0; i<=alto; i++){
  34. for(int j=0; j<=ancho; j++){
  35. if(matriz[i][j]==45){
  36. if(matriz[i-1][j-1]==42)
  37. cont++;
  38. if(matriz[i-1][j]==42)
  39. cont++;
  40. if(matriz[i-1][j+1]==42)
  41. cont++;
  42. if(matriz[i][j-1]==42)
  43. cont++;
  44. if(matriz[i+1][j-1]==42)
  45. cont++;
  46. if(matriz[i+1][j]==42)
  47. cont++;
  48. if(matriz[i+1][j+1]==42)
  49. cont++;
  50. if(matriz[i][j+1]==42)
  51. cont++;
  52. }
  53. if(cont>=6)
  54. celda++;
  55. cont=0;
  56. }
  57.  
  58.  
  59. }
  60.  
  61. return celda;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement