fork(3) download
  1. #include <stdio.h>
  2. int main(void) {
  3. int r, c;
  4. scanf("%d %d", &r, &c);
  5. char cake[r][c];
  6. int i, j, cnt=0, cou=0, a=0, b=0, cell=0;
  7. //reject "\n"
  8. for(i=0;
  9. i<r;
  10. i++) {
  11. for(j=0;
  12. j<c;
  13. j++) {
  14. scanf("%c", &cake[i][j]);
  15. }
  16.  
  17. }
  18. // debug
  19. // printf("%c\n", cake[0][0]);
  20. // printf("%c\n", cake[0][1]);
  21. // printf("%c\n", cake[0][2]);
  22. // printf("%c\n", cake[0][3]);
  23. // printf("%c\n", cake[2][2]);
  24. for(i=0;
  25. i<r;
  26. i++) {
  27. for(j=0;
  28. j<c;
  29. j++) {
  30. cnt++;
  31. if(cake[i][j]=='S') {
  32. cnt=0;
  33. break;
  34. }
  35. }
  36. if(cnt>0) {
  37. a++;
  38. }
  39. }
  40. for(j=0;
  41. j<c;
  42. j++) {
  43. for(i=0;
  44. i<r;
  45. i++) {
  46. cou++;
  47. if(cake[i][j]=='S') {
  48. cou=0;
  49. break;
  50. }
  51. }
  52. if(cou>0) {
  53. b++;
  54. }
  55. }
  56. cell=cnt + cou - a*b;
  57. printf("%d",
  58. cell);
  59. return 0;
  60. }
Success #stdin #stdout 0s 2252KB
stdin
3 4
S...
....
..S.
stdout
8