Posts

Showing posts with the label Hackerearth

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

Who wants to be a Millionaire?-Hackerearth

C++14 Solution #include <iostream> #include <stdio.h> using namespace std; int main() {  int test;  cin >> test;  while (test--) {     int n;     cin >> n;     printf ("%.6f\n", (float)(n-1)*1.0/(float)(n));  }     return 0; } Try this on Hackerearth   For more Hackerearth Problems

Monk's Choice Of Numbers-Hackerearth

JAVA Solution import java.util.*; class TestClass {     public static void main(String args[] ) throws Exception {         Scanner s = new Scanner(System.in);         int t = s.nextInt();         while(t!=0)         {             ArrayList<Integer>hs = new ArrayList<Integer>();             int n = s.nextInt(), k = s.nextInt(), i, count=0;             int ar[] = new int[n];             for(i=0;i<n;i++)             {                 ar[i] = s.nextInt();                 String str = Integer.toBinaryString(ar[i]);                 str = str.replaceAll("0","");                 hs.add(str.length());             }             int len = hs.size();             Integer ak[] = new Integer[len];             hs.toArray(ak);             Arrays.sort(ak);             i=0;len--;             while(i<k)             {                 count+=ak[len];                 i++;                 len--;             }             System.out.println(count);             t--;   

Interval Count - Hackerearth

C++ 14 Solution #include<iostream> using namespace std; int main() {       int t ;       cin>>t;         while(t!=0)         {             int count = 0,i, n ;long long int l , r ,tmp = 0;             cin>>n;             cin>>l>>r;             int p[n];             long long int l1[r+1]={0};             tmp = l;             for(i=0;i<n;i++)             {                 cin>>p[i];                 while(l<=r)                 {                     if(l%p[i]==0&&l1[l]==0)                     {                         count++;                         l1[l]=1;                     }                                         l++;                 }                l = tmp;             }             cout<<count<<endl;             t--;         }     return 0; }     If anyone come up with better solution leave it in comment. Keep Programming...!!!

Nobita and String - Hackerearth

JAVA Solution import java.util.Scanner; class Test { public static void main(String [] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while(t-- > 0) { String s = sc.nextLine(); String str[] = s.split(" "); for(int i = str.length - 1; i >= 0; i--) System.out.print(str[i] + " "); System.out.println(); } } } To try this on Hackerearth

Special Matrix - Hackerearth

C++ 14 Solution      #include<iostream>     using namespace std;     int main()     {          int t ;          cin>>t;             while(t!=0)             {                 int n;                 cin>>n;                 int mid = n/2+1;                 char ar[n+1][n+1];                 int i, j, k, l;                 for(i=1;i<=n;i++)                 {                     for(j=1;j<=n;j++)                     {                         cin>>ar[i][j];                         if(ar[i][j]=='*')                         {                             k=i;                             l=j;                         }                     }                 }                 cout<<abs(mid-k)+abs(mid-l)<<endl;                 t--;             }         return 0;     }    Click this link to try it on Hackerearth