Id and Ship Codechef Solution

Id and Ship Codechef Solution

Problem

Write a program that takes in a letter class ID of a ship and display the equivalent string class description of the given ID. Use the table below.

Class ID Ship Class

B or b BattleShip

C or c Cruiser

D or d Destroyer

F or f Frigate

Input

The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains a character.

Output

For each test case, display the Ship Class depending on ID, in a new line.

Constraints

  • 1 <= T <= 1000

Example

Input:

3
B
c
D

Output:

BattleShip
Cruiser
Destroyer

Id and Ship – CodeChef Solution in Python

T = int(input())
for i in range(T):
    n = input()
    if (n =="B" or n == "b"):
        print("BattleShip")
    elif (n == "C" or n == "c"):
        print("Cruiser")
    elif (n == "D" or n == "d"):
        print("Destroyer")
    else:
        print("Frigate")

Id and Ship – CodeChef Solution in CPP

#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace::std;
int main(int argc, const char * argv[]) {
    int t;
    cin >> t;
    while (t--) {
        char n;
        cin >> n;
        n = toupper(n);
        switch (n) {
            case 'B':
                cout << "BattleShip" << endl;
                break;
            case 'C':
                cout << "Cruiser" << endl;
                break;
            case 'D':
                cout << "Destroyer" << endl;
                break;
            default:
                cout << "Frigate" << endl;
                break;
        }
    }
    return 0;
}

Id and Ship – CodeChef Solution in JAVA

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner input =new Scanner(System.in);
        int t=input.nextInt();
        char ch;
        while(t-->0)
        {
            ch=input.next().charAt(0);
            if(ch=='B' || ch=='b')
                System.out.println("BattleShip");
            else if(ch=='C' || ch=='c')
                System.out.println("Cruiser");
            else if (ch=='D' || ch=='d')
                System.out.println("Destroyer");
            else if(ch=='F' || ch=='f')
                System.out.println("Frigate");
        }
    }
}

Disclaimer: The above Problem (Id and Ship) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment