Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
akashpatek committed Sep 26, 2017
1 parent 77e52bc commit 96a75e9
Show file tree
Hide file tree
Showing 114 changed files with 1,038 additions and 7 deletions.
Binary file added Algorithm/all_possible_permutation
Binary file not shown.
11 changes: 11 additions & 0 deletions Algorithm/all_possible_permutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <bits/stdc++.h>

using namespace std;

int main(){
char ex[]="abc";
do{

cout<<ex<<endl;
}while(next_permutation(ex,ex+3));
}
Binary file added Algorithm/combination_taking_r_at_a_time
Binary file not shown.
26 changes: 26 additions & 0 deletions Algorithm/combination_taking_r_at_a_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <algorithm>
#include <vector>


using namespace std;
int main() {
int n, r;
std::cin >> n;
std::cin >> r;
string ex="abcd";
std::vector<bool> v(n);
std::fill(v.begin(), v.begin() + r, true);

do {
for (int i = 0; i < n; ++i) {
if (v[i]) {
cout<<ex[i];
//std::cout << (i + 1) << " ";
}
}
cout<<endl;
std::cout << "\n";
} while (std::prev_permutation(v.begin(), v.end()));
return 0;
}
Binary file added Algorithm/geek_permutation
Binary file not shown.
42 changes: 42 additions & 0 deletions Algorithm/geek_permutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// C program to print all permutations with duplicates allowed
#include <stdio.h>
#include <string.h>

/* Function to swap values at two pointers */
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}

/* Function to print permutations of string
This function takes three parameters:
1. String
2. Starting index of the string
3. Ending index of the string. */
void permute(char *a, int l, int r)
{
int i;
if (l == r)
printf("%s\n", a);
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permute(a, l+1, r);
swap((a+l), (a+i)); //backtrack
}
}
}

/* Driver program to test above functions */
int main()
{
char str[] = "ABC";
int n = strlen(str);
permute(str, 0, n-1);
return 0;
}
32 changes: 32 additions & 0 deletions My-Solved-Problem/Topcoder/SRM647/PeacefulLine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <bits/stdc++.h>
using namespace std;

class PeacefulLine{
public:
string makeLine(vector <int> x){
int m=-1,ex[26]={};
for(int i=0;i<x.size();i++){
ex[x[i]]++;
}
for(int i=0;i<26;i++){
if(ex[i]>m)
m=ex[i];
}
int r= x.size()-m*2 ;
if(r >= -1)
return "possible";
else
return "impossible";

}
};

int main(){

vector <int> x = {
1,2,3,4
};

PeacefulLine t;
cout<< t.makeLine(x)<<endl;
}
Binary file not shown.
Empty file.
25 changes: 18 additions & 7 deletions My-Solved-Problem/Topcoder/SRM650/d2_250_TaroJiroDividing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ using namespace std;

class TaroJiroDividing{
public:
int gcd(int x,int y);
int getNumber(int a,int b);
};

int TaroJiroDividing::gcd(int x,int y){
return 5;
}

int TaroJiroDividing::getNumber(int a, int b){
return gcd(3,4);

if(a>b){
int t=b;
b=a;
a=t;
}
int l=log2(b/a);
cout<<"l :"<<l<<endl;
if(pow(2,l)*a==b){
int c=0;
while(!(1<<c & a)){
c++;
}
return ++c;
}
}

int main(){
TaroJiroDividing t;
int a,b;
cout<<t.getNumber(a,b);
}
while(cin>>a>>b)
cout<<t.getNumber(a,b)<<endl;
}
Binary file not shown.
6 changes: 6 additions & 0 deletions My-Solved-Problem/Topcoder/SRM650/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
8 4
4 7
12 12
24 96
1000000000
999999999
Binary file added SRC/1's_Cluster.exe
Binary file not shown.
Binary file added SRC/1's_Cluster.o
Binary file not shown.
Binary file added SRC/Basic_string
Binary file not shown.
21 changes: 21 additions & 0 deletions SRC/Basic_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
string s(10u, ' '); // Create a string of ten blanks.

const char* A = "this is a test";
s += A;
cout<<s<<endl;
cout << "s = " << (s + '\n');
cout << "As a null-terminated sequence: " << s.c_str() << endl;
cout << "The sixteenth character is " << s[15] << endl;

reverse(s.begin(), s.end());
s.push_back('\n');
string name="Ashik ";
name.pop_back();
name.pop_back();
cout<<"|"<<name<<"|"<<endl;
cout << s;
}
Binary file added SRC/Basic_string.exe
Binary file not shown.
Binary file added SRC/Basic_string.o
Binary file not shown.
184 changes: 184 additions & 0 deletions SRC/Binary_search_tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#include <iostream>
#include <vector>

using namespace std;

template<class T>
struct Node{
T value;
Node<T>* left;
Node<T>* right;

Node(T _value){
value = _value;
left = NULL;
right = NULL;
}
};

template<class T>
class BST{
private:
Node<T>* root;
public:
BST(){
root = NULL;
}

void insertHelper(Node<T>* &current, T value){
if(current==NULL){ // We have reached bottom of the tree
// Base case
current = new Node<T>(value);
}else{
if(value<current->value){
insertHelper(current->left, value); // going to the left
}else if(value>current->value){
insertHelper(current->right, value); // going to the right
}
}
}

void insert(T value){
if(isEmpty()) root = new Node<T>(value); // tree is empty
else{
// the tree is not empty
insertHelper(root, value);
}
}

bool hasHelper(Node<T>* current, T value){
bool f = false;
if(current!=NULL){
if(current->value == value) return true; // match found
else{
if(value<current->value){ // search in the left side
f = hasHelper(current->left, value);
}else{ // search in the right side
f = hasHelper(current->right, value);
}
}
}
return f;
}

bool has(T value){
// return true if the value is in the tree, else return false
return hasHelper(root, value);
}

bool isEmpty(){
return (root==NULL);
}

void prefix(Node<T>* current){
if(current!=NULL){
cout<<current->value<<" ";
prefix(current->left);
prefix(current->right);
}
}

void infix(Node<T>* current){
if(current!=NULL){
infix(current->left);
cout<<current->value<<" ";
infix(current->right);
}
}

void postfix(Node<T>* current){
if(current!=NULL){
postfix(current->left);
postfix(current->right);
cout<<current->value<<" ";
}
}

void display(int order=0){
if(order==0) prefix(root);
else if(order==1) infix(root);
else if(order==2) postfix(root);
cout<<endl;
}

bool deleteValueHelper(Node<T>* parent, Node<T>* current, T value) {
//cout<<current->value<<endl;
if (!current) return false;
if (current->value == value) {

//if(current)cout<<"ff"<<current->value<<endl;
if (current->left == NULL || current->right == NULL) {

Node<T>* temp = current->left;
if (current->right) temp = current->right;


if (parent) {

if (parent->left == current) {
parent->left = temp;

} else {
parent->right = temp;
}
} else {
root = temp;
}


} else {
Node<T>* validSubs = current->right;
while (validSubs->left) {
validSubs = validSubs->left;
}
T temp = current->value;
current->value = validSubs->value;
validSubs->value = temp;
return deleteValueHelper(current, current->right, temp);
}
//if(current)cout<<"ff"<<current->value<<endl;
delete current;
//cout<<parent->left->value<<endl;
return true;
}
if(current->value > value)
return deleteValueHelper(current, current->left, value);
return deleteValueHelper(current, current->right, value);
}


bool deleteValue(T value) {
Node<T>* parent=NULL;
return deleteValueHelper(parent, root, value);
}
};


int main(){
BST<int> firstTree; // We are creating the binary tree, it is empty
//BST<string> tree2;
//BST<double> tree3;
//BST<char> tree4;
//BST<Student> tree5;
//BST<List<int>> tree6;
//List<BST<int>> tree7;
int nums[] = {10, 7, 5, 6, 12, 11, 15};
int c = 7;

for(int i=0;i<c;i++){
firstTree.insert(nums[i]);
}

firstTree.display(1);
firstTree.deleteValue(15);
firstTree.display(1);
firstTree.deleteValue(5);
firstTree.display(1);
firstTree.deleteValue(10);
firstTree.display(1);
firstTree.deleteValue(7);
firstTree.display(1);
cout<<firstTree.has(999999)<<endl;

return 0;
}
Binary file added SRC/Binary_search_tree.exe
Binary file not shown.
Binary file added SRC/Binary_search_tree.o
Binary file not shown.
17 changes: 17 additions & 0 deletions SRC/Bitset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
const bitset<12> mask(2730);
cout << "mask = " << mask << endl;

bitset<12> x(8);
cout<<x.to_ulong()<<endl;
cout << "Enter a 12-bit bitset in binary: ";
if (cin >> x) {
cout << "x = " << x << endl;
cout << "As ulong: " << x.to_ulong() << endl;
cout << "And with mask: " << (x & mask) << endl;
cout << "Or with mask: " << (x | mask) << endl;
}
}
Binary file added SRC/Bitset.exe
Binary file not shown.
Binary file added SRC/Bitset.o
Binary file not shown.
Binary file added SRC/Count
Binary file not shown.
11 changes: 11 additions & 0 deletions SRC/Count.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int A[] = { 2, 0, 2, 6, 0, 3, 1, -7 };
const int N = sizeof(A) / sizeof(int);

cout << "Number of zeros: "
<< count(A, A + N, 2)
<< endl;
}
Binary file added SRC/Fibonicci
Binary file not shown.
Loading

0 comments on commit 96a75e9

Please sign in to comment.