In this HackerRank Kitty and Katty problem solution, we have given the value of N plastic blocks. Do we need to find and print the name of the winner? Assume both plays optimally.

HackerRank Kitty and Katty problem solution


Problem solution in Python.

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    T = int(input())

    for T_itr in range(T):
        n = int(input())
        if(n==1):
            print("Kitty")
        elif(n%2==0):
            print("Kitty")
        else:
            print("Katty")


Problem solution in Java.

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

public class KittyAndKatty {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int t = nextInt();
		while (t-- > 0) {
			int n = nextInt();
			out.println((n > 1 && n % 2 == 1) ? "Katty" : "Kitty");
		}
	}

	KittyAndKatty() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new KittyAndKatty();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


Problem solution in C++.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;


int main(){
    int T;
    cin >> T;
    for(int a0 = 0; a0 < T; a0++){
        int n;
        cin >> n;
        if(n==1)
            cout<<"Kitty"<<endl;
        else if(n%2==0)
            cout<<"Kitty"<<endl;
        else
            cout<<"Katty"<<endl;
    }
    return 0;
}


Problem solution in C.

#include<stdio.h>
#include<string.h>
main()
{
    int u;
    scanf("%d",&u);
    while(u!=0)
    {
    int n;
    scanf("%d",&n);
     
        if(n==1){
          printf("Kitty\n");  
        }
        else if(n%2==0){
          printf("Kitty\n");   
        }
        else{
            printf("Katty\n");  
         
        }

    u--;
    }

}