Facing the sun

PROBLEM :

An array of buildings is facing the sun. The heights of the building is given in an array. You have to tell which all buildings will see the sunset.

Input:

The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,N is the number of buildings.
The second line of each test case contains N input H[i],height of building.

Output:

Print the total number of buildings which will see the sunset.

Constraints:

1 = T = 100
1 = N = 500
1 = H[i] = 1000

Example:

Input:
2
5
7 4 8 2 9
4
2 3 4 5

Output:
3
4

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
int main()
 {
int t,no,a[1000],i,top,count ;
cin>>t ;
while(t--)
{
   cin>>no ;
   for(i=0;i<no;i++)
   cin>>a[i] ;
   count=1 ;
   top=a[0] ;
   for(i=0;i<no;i++)
   {
       if(a[i]>top)
       {top=a[i];count++ ;}
   }
 
   cout<<count<<endl ;
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )