Wednesday, March 29, 2017

Id and Ship

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
Battle Ship
C or c
Cruiser
D or d
Destroyer
F or f
Frigate

Input
The first line contains an integer T, total number of test cases. Then follow T lines, each line contains a character.

Output
Display the Ship Class depending on ID.

Constraints
1 ≤ T ≤ 1000


#include <stdio.h>
int main()
{   int n,i;
    char ch;
    scanf("%d",&n);
    for(i=0;i<2*n;i+=1)
    {   scanf("%c",&ch);
        switch(ch)
        {   case 'b': printf("BattleShip\n");
                    break;
            case 'B': printf("BattleShip\n");
                    break;
            case 'c': printf("Cruiser\n");
                    break;
            case 'C': printf("Cruiser\n");
                    break;
            case 'd': printf("Destroyer\n");
                    break;
            case 'D': printf("Destroyer\n");
                    break;
            case 'f': printf("Frigate\n");
                    break;
            case 'F': printf("Frigate\n");
                    break;
        }  
    }  
    return 0;

}

2 comments:

  1. If input is 1 and B ...then output is Battleship ...
    And if input is 2 F f ...then output is Frigate

    ReplyDelete
  2. If input is 3 B c D then out is battleship crusier destroyer

    ReplyDelete