Hackerrank Cut The Stick Solution

This is the solution of cut the stick problem under implementation sub domain. You can refer the question Here.

Output :


Code :

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int mi,n,c=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int i=0;
    while(a[n-1]>0)
    {
        c=0;
       int x=a[i];
       if(a[i]>0)
       {

           for(int i=0;i<n;i++)
                a[i]=a[i]-x;
           c=n-i;cout<<c<<endl;
       }
       else
       {
           i++;
       }
       //cout<<endl;
    }
    return 0;
}

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Bit Stuffing Code Implementation in Java

Hackerrank Modified Kaprekar Numbers Solution