Advertisement
PGhosh

C Problem

Mar 19th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. A nice part of the Roman Catholic Mass is the rite of peace when people shake hands with their neighbors and say "peace be with you". Mirko has found a way to turn this ritual into his own favor. Inside the church, there are R rows of benches where each row can hold a capacity of S people. We can imagine the seating order as a matrix sized R x S where each element represents either a person or an empty seating space. Let us assume that each person shakes hands with their neighbors. That means that the neighbors are located in one of the eight neighboring elements (if such element exists):
  2.  
  3. A seating order of the people inside the church has been given before Mirko enters. Mirko is, of course, late for the morning Mass and will sit in an empty space so that he shakes hands with as many people as he can. If there are no empty seats left, Mirko will simply give up on the idea and go to the evening Mass instead. We can assume that nobody enters the church after Mirko.
  4.  
  5. Calculate the total number of handshakes given during the morning Mass.
  6.  
  7. Input
  8.  
  9. The first line of input contains positive integers R and S (1 ≤ R, S ≤ 50) as stated in the text. Each of the following R lines contains S characters. These R x S characters represent the seating order. The character '.' (Dot) represents an empty place and the character 'o' (lowercase letter o) represents a person.
  10.  
  11. Output
  12.  
  13. The first and only line of output should contain the required number of handshakes.
  14.  
  15. Samples
  16. Input Output
  17. 2 3 2
  18. ..o
  19. o..
  20. Input Output
  21. 2 2 6
  22. oo
  23. oo
  24.  
  25.  
  26. Clarification of the first example
  27.  
  28. Mirko will sit in a way that he can shake hands with both persons, which gives us two possibilities:
  29.  
  30. .oo
  31. o..
  32.  
  33. ..o
  34. oo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement