#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
int i;
for(i=0;i<t;i++)
{
char c[1];
scanf("%c",&c[0]);
if(c[0]==‘B’||c[0]==‘b’)
{
printf(“Battleship\n”);
}
else if(c[0]==‘C’||c[0]==‘c’)
{
printf(“Cruiser\n”);
}
else if(c[0]==‘D’||c[0]==‘d’)
{
printf(“Destroyer\n”);
}
else if(c[0]==‘F’||c[0]==‘f’)
{
printf(“Frigate\n”);
}
}
return 0;
}
Which problem are you trying to solve?
2 Likes
FLOW010
I cant understand your language very well. How about you see my solution in Java, I just solved and maybe you can understand something.
Here: CodeChef: Practical coding for everyone
1 Like
It’s BattleShip not Battleship.
newline or enter is also a character . Your c[0] char array contains ‘\n’ . To avoid it you can use fflush or simply update your code
scanf("%d ",&t);
scanf("%c ",&c[0]);
Here is a space before the end of double quote.
2 Likes
char ch;
std::scanf("%d", &t);
std::scanf(" %c", &ch); // ignore the endline after %d, then read a char
1 Like