Posts

Cut the sticks

Cut the sticks     You are given   sticks, where the  length  of each stick is a positive integer. A  cut operation  is performed on the sticks such that all of them are reduced by the length of the smallest stick. ---Solution--- #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int compare (const void * a, const void * b) {   return ( *(int*)a - *(int*)b ); } int main() {     /* Enter your code here. Read input from STDIN. Print output to STDOUT */        int element,k;     cin>>element;     int array[element];     for(int i=0;i<element;i++)         {             cin>>array[i];     }      qsort (array, element, sizeof(int), compare);     int p=element;     for(int i=0;i<element;i++)         {                            if(array[i]!=0)              {cout<<p<<endl;          if(p<=1)          {break;}             for(int j=element-1;j>=i;j--)    

Library Fine

Library Fine Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows: If the book is returned on or before the expected return date, no fine will be charged (i.e.:  . If the book is returned after the expected return  day  but still within the same calendar month and year as the expected return date,  . If the book is returned after the expected return  month  but still within the same calendar year as the expected return date, the  . If the book is returned after the calendar  year  in which it was expected, there is a fixed fine of  . --Solution-- #include<stdio.h> int main() {         unsigned int dd1,mm1,yy1;         unsigned int dd2,mm2,yy2;         int dif=0;         scanf("%d%d%d",&dd1,&mm1,&yy1);         scanf("%d%d%d",&dd2,&mm2,&yy2);     if(dd1==6 &&

Sherlock and Squares

Sherlock and Squares Watson gives two integers (  and  ) to Sherlock and asks if he can count the number of square integers between   and   (both inclusive). Note : A square integer is an integer which is the square of any integer. For example,  1 ,  4 ,  9 , and  16  are some of the square integers as they are squares of  1 ,  2 ,  3 , and  4 , respectively. Input Format The first line contains  , the number of test cases.   test cases follow, each in a new line.  Each test case contains two space-separated integers denoting   and  . --Solution-- #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() {     int t,i,l;    unsigned int x,y,j,k;    cin>>t;      for(i=0;i<t;i++)         {cin>>x>>y;l=0;         for(j=1;j<=y;j++)             {               k=j*j;             if(k>=x && k<=y)