From 735860843d6c6480f2e250797f220aa9618e0a80 Mon Sep 17 00:00:00 2001 From: TANU0208 Date: Tue, 11 Oct 2022 23:41:08 +0530 Subject: [PATCH] This is my code in cpp --- TANU SINGH/Fabonacci through Recursion.cpp | 20 +++++++++ ...ray is sorted or not through Recursion.cpp | 21 ++++++++++ ...ans Last Occurence of a no in an array.cpp | 41 +++++++++++++++++++ ...requency of that string(unordered map).cpp | 26 ++++++++++++ TANU SINGH/Sum of Subarrays.cpp | 28 +++++++++++++ TANU SINGH/Tower_of_Hanoi.cpp | 22 ++++++++++ ...que strings in lexographical order STL.cpp | 23 +++++++++++ 7 files changed, 181 insertions(+) create mode 100644 TANU SINGH/Fabonacci through Recursion.cpp create mode 100644 TANU SINGH/Finding if array is sorted or not through Recursion.cpp create mode 100644 TANU SINGH/First ans Last Occurence of a no in an array.cpp create mode 100644 TANU SINGH/N strings and Q queries in each query you are given an string, print frequency of that string(unordered map).cpp create mode 100644 TANU SINGH/Sum of Subarrays.cpp create mode 100644 TANU SINGH/Tower_of_Hanoi.cpp create mode 100644 TANU SINGH/print unique strings in lexographical order STL.cpp diff --git a/TANU SINGH/Fabonacci through Recursion.cpp b/TANU SINGH/Fabonacci through Recursion.cpp new file mode 100644 index 00000000..ad7e1918 --- /dev/null +++ b/TANU SINGH/Fabonacci through Recursion.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +int fib (int n) +{ + if (n==0 || n==1) + return n; + + else + return fib(n-1) + fib(n-2); +} + +int main() +{ + int n; + cin>>n; + cout< +using namespace std; + +bool Sorted (int arr[], int n) +{ + if(n==1) + return true; + + else + { + bool restarray = Sorted(arr+1, n-1); + return (arr[0] +using namespace std; + +int firstocc (int arr[], int n, int i, int key) +{ + if(i==n){ + return -1; + } + if(arr[i] == key){ + return i; + } + + return firstocc (arr,n,i+1,key); +} + +int lastocc (int arr[], int n, int i, int key) +{ + if(i==n){ + return -1; + } + + int restarr = lastocc(arr,n,i+1,key); + if (restarr!= -1) + return restarr; + + if(arr[i]==key) + return i; + + return -1; + +} + +int main() +{ + + int arr[] = {5,6,7,7,8}; + cout< +#include +using namespace std; + +int main() +{ + unordered_map m; + int n; + cin>>n; + + for(int i=0; i>s; + m[s]++; + } + + int q; + cin>>q; + while(q--){ + string s; + cin>>s; + cout< +using namespace std; + +int main() +{ + int n; + int sum = 0; //stores the sum of the subarray + cout<<"enter the size of the array\n"; + cin>>n; //inputing the size of the array from the array + int A[n]; + cout<<"Enter the elments of the array\n"; + + for(int i=0; i>A[i]; + } + + for(int i=0; i +using namespace std; + +void TowerOfHanoi(int n, char src, char dest, char help) +{ + + if(n==0) + return; + + TowerOfHanoi(n-1,src,help,dest); + cout<<"Move from "< +#include +using namespace std; + +int main() +{ + int n; + cin>>n; + + map m; + + for(int i=0; i>s; + m[s]++; + } + + for(auto pr:m){ + cout<