fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5.  
  6. int
  7. max (int a, int b)
  8. {
  9. return a > b ? a : b;
  10. }
  11.  
  12. int
  13. min (int a, int b)
  14. {
  15. return a < b ? a : b;
  16. }
  17.  
  18. int
  19. protect_value (int value)
  20. {
  21. return max(0, min(7, value));
  22. }
  23.  
  24. bool
  25. is_terminal (char c)
  26. {
  27. return (c == ' ') || (c == '\n') || (c == EOF) || (c == '\t');
  28. }
  29.  
  30. int
  31. main (void)
  32. {
  33. bool is_free[8][8];
  34. signed short next_letter;
  35. for(int i = 0; i < 8; i++)
  36. {
  37. for(int j = 0; j < 8; j++)
  38. {
  39. is_free[i][j] = 1;
  40. }
  41. }
  42. while (!is_terminal(next_letter = getchar()))
  43. {
  44. signed short next_digit = getchar();
  45. int x = next_letter - 'a', y = next_digit - '1';
  46. for (int i = -1; i <= 1; i++)
  47. {
  48. for (int j = -1; j <= 1; j++)
  49. {
  50. is_free[protect_value(x + i)][protect_value(y + j)] = 0;
  51. }
  52. }
  53. }
  54. int answer = 0;
  55. for (int i = 0; i < 8; i++)
  56. {
  57. for (int j = 0; j < 8; j++)
  58. {
  59. answer += is_free[i][j] ? 1 : 0;
  60. }
  61. }
  62. printf("%d", answer);
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0s 4468KB
stdin
h7h8
stdout
58