#include <bits/stdc++.h> using namespace std ; int fact ( int n){ //1st step Base Case if (n== 0 ){ return 1 ; } int smallans = fact(n- 1 ) ; // 2nd step Assumption Recursive Case int ans = n*smallans ; //3rd step Calculation return ans ; } int main (){ int n ; cin >> n ; cout << fact(n) << ' \n ' ; return 0 ; }
// # CODE: TREE2 // first line of input contains the testcases // next line contains number of sticks (n) and the next line // contains height of the sticks // logic: // we input the heights of sticks into a list (sticks) // then we extract all the unique elements of the sticks // and append them to a new list (uniqueHeight) the length // of the unique list will be number of passes required to // cut the sticks because the number of passes will be equal // to the number of unique elements in the list. The cut part // should be equal i.e., h - H should be equal for all the sticks // being cut. #include <iostream> #include <algorithm> using namespace std ; int remove_duplicates ( long int a[] , long int temp1){ if (temp1 == 0 || temp1 == 1 ) return temp1 ; long int temp2[temp1] ; long int j = 0 ; for ( long int i = 0 ; i < temp1 - 1 ; ++i) { if (a[i] != a[i+ 1 ]){
Comments
Post a Comment