fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int x, y;
  6. cin >> x >> y; // nhap toa do cua quan Ma (cot x, dong y)
  7. // 8 huong di chuyen co the cua quan Ma
  8. int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
  9. int dy[] = {1, -1, 1, -1, 2, -2, 2, -2};
  10. int count = 0; // bien dem so o co the di duoc
  11. for (int i = 0; i < 8; i++) {
  12. int nx = x + dx[i]; // toa do cot moi
  13. int ny = y + dy[i]; // toa do dong moi
  14. // kiem tra neu vi tri moi van nam trong ban co
  15. if (nx >= 1 && nx <= 8 && ny >= 1 && ny <= 8) {
  16. count++; // tang bien dem
  17. }
  18. }
  19. cout << count << endl; // in ra ket qua
  20. return 0;
  21. }
  22.  
  23.  
Success #stdin #stdout 0.01s 5292KB
stdin
5 4
stdout
8