Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

HackerRank A Chessboard Game problem solution

YASH PAL, 31 July 2024

In this HackerRank A Chessboard Game problem solution we have Given the initial coordinates of the players’ coins, assuming optimal play, determine which player will win the game.

HackerRank A Chessboard Game problem solution

Topics we are covering

Toggle
  • Problem solution in Python.
  • Problem solution in Java.
  • Problem solution in C++.
  • Problem solution in C.

Problem solution in Python.

t = int(input())
for _ in range(t):
    x , y = map(int,input().split())
    if x%4==0 or x%4 ==3 or y%4==0 or y%4==3:
        print("First")
    else:
        print("Second")

Problem solution in Java.

import java.io.*;
import java.util.*;

public class Solution {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    for(int i = 0; i < n; i++) {
      int playerX = in.nextInt();
      int playerY = in.nextInt();
      System.out.println(findWinner(playerX, playerY));
    }
  }

  public static String findWinner(int x, int y) {
    return (x-1)%4<2 && (y-1)%4<2? "Second" : "First";
  }
}

Problem solution in C++.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int t, z, x, y;
    cin >> t;
    for (z=0; z<t; z++)
    {
        cin >> x >> y;
        x %= 4;
        y %= 4;
        if (x==0 || x==3 || y==0 || y==3) cout << "Firstn";
        else                              cout << "Secondn";
    }
    return 0;
}

Problem solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int t, m, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d", &m, &n);
        int i = m % 4;
        int j = n % 4;
        if ((i == 1 || i == 2) && (j == 1 || j == 2)) {
            printf("Secondn");
        } else {
            printf("Firstn");
        }
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}

Algorithms coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes