Wednesday, March 29, 2017

Chef and Dolls

Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which all dolls have paired. One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing/

Input
The first line contains the number of test cases.
Second line of the input contains the number of elements in the array.
The next n lines are the types of each doll that is left.

Output
Find the type of doll that doesn't have a pair

Constraints
1<=T<=10
1<=N<=100000 (10^5)
1<=ti<=100000


#include <stdio.h>
int main()
{   int i,j,c,z,y,x[100000],k,a[100000],b,n,m,t;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {   scanf("%d",&n);
        for(j=0;j<n;j++)
            scanf("%d",&a[j]);
        y=0;
        for(j=0;j<n;j++)
        {   b=a[j];
            c=0;
            for(m=0;m<n;m++)
                        if(a[m]==b)
                            c++;
            if(c%2!=0)
            {   for(z=0;z<=y;z++)
                    if(x[z]==b)
                        break;
                    else
                        printf("%d\n",b);
                x[y]=b;
            }
        }
    }
    return 0;
}

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;

}

First and Last Digit

If Give an integer N, Write a program to obtain the sum of the first and last digit of this number.

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

Output
Display the sum of first and last digit of N.

Constraints
1 ≤ T ≤ 1000
1 ≤ N ≤ 1000000


#include <stdio.h>
int main()
{   int t,i,n,x;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {   scanf("%d",&n);
        if(n<10)
            printf("%d",n);
        else
        {   x=n%10;
            while(n>=10)
                n=n/10;
            x+=n;
            printf("%d\n",x);
        }
    }
    return 0;
}

Valid Triangles

Write a program to check whether a triangle is valid or not, when the three angles of the triangle 
are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degress.

Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three angles A, B and C of triangle separated by space.

Output
Display 'YES' or 'NO' if the triangle is Valid or not respectively.

Constraints
1 ≤ T ≤ 1000
40 ≤ A,B,C ≤ 180

#include <stdio.h>
int main()
{   int t,i,n,x,y,z;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {   scanf("%d",&x);
        scanf("%d",&y);
        scanf("%d",&z);
        if(((x+y+z)==180)&&(x>0)&&(y>0)&&(z>0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;


}