Canna

Sunday, 23 September 2018

ID and SHIP

Problem Description

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

  • Test Case 1

    Input (stdin)
    1
    
    B
    
    
    Expected Output
    BattleShip
  • Test Case 2

    Input (stdin)
    2
    
    F
    
    f
    
    
    Expected Output
    Frigate
    
    Frigate
  • Program
  • #include <stdio.h>
    int main() 
    {
     int N;
     char ch,temp;
     scanf("%d",&N);
     scanf("%c",&temp);
     while(N--)
     {
         scanf("%c",&ch);
         scanf("%c",&temp);
         if(ch=='F'||ch=='f')
         {
             printf("Frigate\n");
         }
         else if(ch=='B'||ch=='b')
         {
             printf("BattleShip\n");
         }
         else if(ch=='C'||ch=='c')
         {
             printf("Cruiser\n");
         }
         else if(ch=='D'||ch=='d')
         {
             printf("Destroyer\n");
         }
     }
     return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.