fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int h, w, x, y;
  5. char s[100][100];
  6.  
  7. scanf("%d %d %d %d\n", &h, &w, &x, &y);
  8. for (int i=0; i<h; i++){
  9. scanf("%s\n", s[i]);
  10. }
  11.  
  12. int cnt=1;
  13. int ix=x-1;
  14. int iy=y-1;
  15. // 右方向の探索
  16. for (ix=x; ix<h; ix++){
  17. if(s[ix][iy]=='#') break;
  18. cnt++;
  19. }
  20. // 左方向の探索
  21. for (ix=x-2; ix>=0; ix--){
  22. if(s[ix][iy]=='#') break;
  23. cnt++;
  24. }
  25. ix=x-1;
  26. // 下方向の探索
  27. for (iy=y; iy<w; iy++){
  28. if(s[ix][iy]=='#') break;
  29. cnt++;
  30. }
  31. // 上方向の探索
  32. for (iy=y-2; iy>=0; iy--){
  33. if(s[ix][iy]=='#') break;
  34. cnt++;
  35. }
  36.  
  37. printf("%d\n", cnt);
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5392KB
stdin
5 5 4 2
.#..#
#.###
##...
#..#.
#.###
stdout
3