Skip to content

This is my code in cpp #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions TANU SINGH/Fabonacci through Recursion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
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<<fib(n)<<endl;
return 0;
}

21 changes: 21 additions & 0 deletions TANU SINGH/Finding if array is sorted or not through Recursion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
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]<arr[1] && restarray);
}
}

int main()
{
int arr[] = {1,2,4,5};
cout<<Sorted(arr,4)<<endl;
return 0;
}
41 changes: 41 additions & 0 deletions TANU SINGH/First ans Last Occurence of a no in an array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
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<<firstocc(arr,5,0,7)<<endl;
cout<<lastocc(arr,5,0,7)<<endl;
return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
unordered_map <string, int>m;
int n;
cin>>n;

for(int i=0; i<n; i++){
string s;
cin>>s;
m[s]++;
}

int q;
cin>>q;
while(q--){
string s;
cin>>s;
cout<<m[s]<<endl;
}

return 0;
}
28 changes: 28 additions & 0 deletions TANU SINGH/Sum of Subarrays.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
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<n; i++) //loop for inputing the elements in the array
{
cin>>A[i];
}

for(int i=0; i<n; i++) //loop to point to the starting
{
sum = 0;
for(int j=i; j<n; j++) //loop to point to the end point of the subarray
{
sum+= A[j]; //calculating the sum of the respective subarray
cout<<"the sum of the subarray is "<<sum<<endl; //printing the summ of the subarray
}
}
return 0;
}
22 changes: 22 additions & 0 deletions TANU SINGH/Tower_of_Hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
TOWER OF HANOI

#include <iostream>
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 "<<src<<" to "<<dest<<endl;
TowerOfHanoi(n-1,help,dest,src);
}

int main()
{
TowerOfHanoi(3,'A','C','B');

return 0;
}
23 changes: 23 additions & 0 deletions TANU SINGH/print unique strings in lexographical order STL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
cin>>n;

map<string, int> m;

for(int i=0; i<n; i++){
string s;
cin>>s;
m[s]++;
}

for(auto pr:m){
cout<<pr.first<<" "<<pr.second<<endl;
}
return 0;
}