Posts

Showing posts with the label C

Naughty Sid and SEV-Hackerearth

C Solution     #include <stdio.h>     #include<math.h>     #define PI 3.14159265     int main()     {        long long int t,i,a,H,o,h;        scanf("%lld",&t);        float x,y;        for(i=0;i<t;i++)        {            scanf("%lld %lld %lld",&a,&H,&o);            x=(1.0*H)/a;            y=tan(o*PI/180.0);            if(x>y)            {                h=ceil(H-(a*y)/2);                           }            else            {                h=ceil((H*H)/(2*a*y));            }            printf("%lld\n",h);        }           return 0;     } To try this on Hackerearth For more Hackerearth Problems

Printing numbers without duplicates

Given input as a string which contains duplicate numbers where duplicates are in an order. You has to print the output in an order without duplicates. INPUT "111122223333" OUTPUT 123 C Solution #include<stdio.h> #include <string.h> int main() {     char str[14];     scanf("%s",str);     for(int i=0;i<strlen(str);i++)     {         printf("%c",str[i]);         if(str[i-1]!=str[i]&&str[i]!=str[i+1])           printf("%c",str[i]);     }   return 0; }  If anyone come up with better solution leave it in comments. Keep Programming..!!