Skip to content
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
28 changes: 28 additions & 0 deletions first_and_last_occurenece_of_Element_of_String.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<bits/stdc++.h>
using namespace std;
void occurence(string str, int idx,char element){
int first,last=-1;
if(idx == str.length()){
cout<<first;
cout<<last;
return;
}
char currChar = str.at(idx);
if(currChar == element){
if(first == -1){
first=idx;
}
else{
last=idx;
}
}
occurence(str,idx+1,element);
}

int main(){
string str;
cin>>str;
char element;
cin>>element;
occurence(str,0,element);
}
25 changes: 25 additions & 0 deletions middle_of_three_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
using namespace std;
int main(){
int A,B,C;
cin>>A>>B>>C;
//if((A-B)*(A-C)<0) return A;
//else if((B-A)*(B-C)<0) return B;
//else return C;
//time taken 5 seconds
//if(A>B) swap(A,B);
//if(B>C)swap(B,C);
//if(A>B) swap(A,B);
//return B;
//4 seconds

//if(A>B && B>C || C>B && B>A)
//return B;
//else if(B>A && A>C || A>B && C>B)
//return A;
//else if(A>B && C>B || B>A && B>C)
//return C;
//worst method 9 seconds

return (A>B && B>C)||(C>B && B>A) ? B : (B>A && A>C)||(C>A && A>B) ? A : C;
}