-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Hero-2000/master
the second
- Loading branch information
Showing
16 changed files
with
805 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
template<class X, int m, int n> | ||
class Matrix{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include<iostream> | ||
#include<vector> | ||
using namespace std ; | ||
int gcd(int x,int y) | ||
{ | ||
if(y==0) | ||
return x ; | ||
else return gcd(y,x%y) ; | ||
} | ||
int main() | ||
{ | ||
int n , d ; | ||
cin>>n>>d ; | ||
|
||
d=d%n ; | ||
vector<int> v(n) ; | ||
for(int i=0 ;i<n ;i++) | ||
cin>>v[i] ; | ||
|
||
for(int i=0 ; i<gcd(n,d) ; i++) | ||
{ | ||
int temp=v[i] ; | ||
int j= i ; | ||
|
||
while(1) | ||
{ | ||
int k=j+d ; | ||
if(k>=n) | ||
k=k-n ; | ||
if(k==i) ; | ||
break ; | ||
v[j] = v[k] ; | ||
j=k ; | ||
} | ||
v[j] = temp ; | ||
} | ||
|
||
for(auto x:v) | ||
cout<<x<<' '; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
vector<string> split_string(string); | ||
|
||
// Complete the libraryFine function below. | ||
int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) { | ||
int fine ; | ||
|
||
if (y1>y2)//return after a year | ||
fine =10000 ; | ||
else if (y1<y2) | ||
fine = 0 ; | ||
else | ||
{ | ||
if(m1>m2) //after a month | ||
fine=500*(m1-m2); | ||
else if(m1<m2) | ||
fine=0 ; | ||
else | ||
{ | ||
if(d1>d2) | ||
fine=15*(d1-d2) ; | ||
else fine = 0 ; | ||
} | ||
} | ||
|
||
|
||
return fine ; | ||
} | ||
|
||
int main() | ||
{ | ||
int r[3] ; | ||
int due[3] ; | ||
cin>>r[0]>>r[1]>>r[2] ; | ||
cin>>due[0]>>due[1]>>due[2]; | ||
|
||
int result = libraryFine( r[0] ,r[1] , r[2] , due[0] , due[1] , due[2] ); | ||
|
||
cout << result << "\n"; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <iostream> | ||
using namespace std; | ||
struct node {int data ; | ||
node *next; | ||
|
||
} ; | ||
|
||
class link | ||
{ | ||
node *start ; | ||
public: | ||
link(); | ||
void input(int i=0); | ||
void output(); | ||
~link(); | ||
void reve() ; | ||
}; | ||
|
||
link::link() | ||
{ | ||
start=nullptr ; | ||
} | ||
|
||
void link::input(int i) | ||
{ | ||
node*temp =new node ; | ||
temp->data=i ; | ||
temp->next=NULL ; | ||
if(start!=NULL) | ||
{ | ||
temp->next=start ; | ||
start =temp ; | ||
} | ||
else | ||
{ | ||
temp->next=NULL; | ||
start=temp ; | ||
} | ||
} | ||
void link::output() | ||
{ | ||
node *temp; | ||
temp=start; | ||
while(temp!=NULL) | ||
{ | ||
cout<<temp->data << " "; | ||
temp=temp->next ; | ||
} | ||
cout<<endl ; | ||
} | ||
link::~link() | ||
{ | ||
while(start!=NULL) | ||
{ | ||
node *temp =start ; | ||
start=start->next ; | ||
delete temp ; | ||
} | ||
cout<<"Done"; | ||
} | ||
|
||
|
||
void link::reve() | ||
{ | ||
cout<<"Reversed\n" ; | ||
node *prev = NULL ; | ||
node *p ; | ||
p=start ; | ||
|
||
while(p!=NULL) | ||
{ | ||
node *temp=p->next; | ||
p->next = prev; | ||
prev = p; | ||
p=temp ; | ||
} | ||
while(prev!=NULL) | ||
{ | ||
cout<<prev->data<<" "; | ||
prev=prev->next ; | ||
} | ||
cout<<endl ; | ||
} | ||
int main() { | ||
|
||
link l; | ||
l.input(4); | ||
l.input(8) ; | ||
l.input(7) ; | ||
l.input(9) ; | ||
l.input(1) ; | ||
l.input(0) ; | ||
l.input(2) ; | ||
l.input(5) ; | ||
l.input(3) ; | ||
l.output(); | ||
|
||
l.reve() ; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
int main() { | ||
unsigned int n ,q, t,x ; | ||
cin>>n ; | ||
vector<int> a(n) ; | ||
for(int i=0; i<n ; i++) | ||
cin>>a[i] ; | ||
|
||
sort(a.begin(),a.end()) ; | ||
cin>>q; | ||
vector<int>::iterator low ; | ||
|
||
while(q--){ | ||
cin>>t ; | ||
low=std::lower_bound (a.begin(), a.end(), t); // | ||
x=low- a.begin() ; | ||
|
||
if(a[x]==t) | ||
cout<<"Yes " ; | ||
else | ||
cout<<"No "; | ||
cout<< (x+1) << '\n'; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include<iostream> | ||
#include "pem.cpp" | ||
|
||
using namespace std ; | ||
int main() | ||
{ | ||
int t; | ||
cout<<pem(10,2); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// See the Cormen book for details of the | ||
// following algorithm | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
int b[10][10]; | ||
void order(int arr[10],int i,int j,char & name) | ||
{ | ||
if(i==j) | ||
{ cout<<name++ ; | ||
return; | ||
} | ||
cout<<"( "; | ||
order(arr,i,b[i][j],name); | ||
order(arr,b[i][j]+1,j,name); | ||
cout<<" )"; | ||
} | ||
void MatrixChainOrder(int p[], int n) | ||
{ | ||
int m[n][n]; | ||
|
||
int i, j, k, L, q; | ||
for (i = 1; i < n; i++) | ||
m[i][i] = 0; | ||
for (L = 2; L < n; L++) | ||
{ | ||
for (i = 1; i < n - L + 1; i++) | ||
{ | ||
j = i + L - 1; | ||
m[i][j] = INT_MAX; | ||
for (k = i; k <= j - 1; k++) | ||
{ | ||
q = m[i][k] + m[k + 1][j] + | ||
p[i - 1] * p[k] * p[j]; | ||
if (q < m[i][j]) | ||
{ | ||
m[i][j] = q; | ||
b[i][j] = k; | ||
} | ||
} | ||
} | ||
} | ||
cout<<" Optimal Parenthesization is :\n"; | ||
char name='A'; | ||
order(p,1,n-1,name); | ||
cout<<"\nEfficient cost is "<< m[1][n - 1]; | ||
} | ||
int main() | ||
{ | ||
int arr[] = {1, 2, 3, 4,5}; | ||
int size = sizeof(arr) / sizeof(arr[0]); | ||
|
||
MatrixChainOrder(arr, size); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
using namespace std; | ||
void heapify(int arr[], int n, int i) | ||
{ | ||
int smallest = i; // Initialize smalles as root | ||
int l = 2 * i + 1; // left = 2*i + 1 | ||
int r = 2 * i + 2; // right = 2*i + 2 | ||
|
||
|
||
if (l < n && arr[l] < arr[smallest]) | ||
smallest = l; | ||
if (r < n && arr[r] < arr[smallest]) | ||
smallest = r; | ||
if (smallest != i) { | ||
swap(arr[i], arr[smallest]); | ||
heapify(arr, n, smallest); | ||
} | ||
} | ||
void heapSort(int arr[], int n) | ||
{ | ||
for (int i = n / 2 - 1; i >= 0; i--) | ||
heapify(arr, n, i); | ||
for (int i = n - 1; i >= 0; i--) { | ||
swap(arr[0], arr[i]); | ||
heapify(arr, i, 0); | ||
} | ||
} | ||
void printArray(int arr[], int n) | ||
{ | ||
for (int i = 0; i < n; ++i) | ||
cout << arr[i] << " "; | ||
cout << "\n"; | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[] = { 4, 6, 3, 2, 9 ,45,1,25}; | ||
int n = sizeof(arr) / sizeof(arr[0]); | ||
heapSort(arr, n); | ||
cout << "Sorted array is \n"; | ||
printArray(arr, n); | ||
} |
Oops, something went wrong.