diff --git a/Algorithm/all_possible_permutation b/Algorithm/all_possible_permutation new file mode 100755 index 0000000..00ebfba Binary files /dev/null and b/Algorithm/all_possible_permutation differ diff --git a/Algorithm/all_possible_permutation.cpp b/Algorithm/all_possible_permutation.cpp new file mode 100644 index 0000000..7de90bb --- /dev/null +++ b/Algorithm/all_possible_permutation.cpp @@ -0,0 +1,11 @@ +#include + +using namespace std; + +int main(){ + char ex[]="abc"; + do{ + + cout< +#include +#include + + +using namespace std; +int main() { + int n, r; + std::cin >> n; + std::cin >> r; + string ex="abcd"; + std::vector v(n); + std::fill(v.begin(), v.begin() + r, true); + + do { + for (int i = 0; i < n; ++i) { + if (v[i]) { + cout< +#include + +/* 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; +} \ No newline at end of file diff --git a/My-Solved-Problem/Topcoder/SRM647/PeacefulLine.cpp b/My-Solved-Problem/Topcoder/SRM647/PeacefulLine.cpp new file mode 100644 index 0000000..19442d5 --- /dev/null +++ b/My-Solved-Problem/Topcoder/SRM647/PeacefulLine.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +class PeacefulLine{ + public: + string makeLine(vector x){ + int m=-1,ex[26]={}; + for(int i=0;im) + m=ex[i]; + } + int r= x.size()-m*2 ; + if(r >= -1) + return "possible"; + else + return "impossible"; + + } +}; + + int main(){ + + vector x = { + 1,2,3,4 + }; + + PeacefulLine t; + cout<< t.makeLine(x)<b){ + int t=b; + b=a; + a=t; + } + int l=log2(b/a); + cout<<"l :"<>a>>b) + cout< +using namespace std; + +int main() { + string s(10u, ' '); // Create a string of ten blanks. + + const char* A = "this is a test"; + s += A; + cout< +#include + +using namespace std; + +template +struct Node{ + T value; + Node* left; + Node* right; + + Node(T _value){ + value = _value; + left = NULL; + right = NULL; + } +}; + +template +class BST{ + private: + Node* root; + public: + BST(){ + root = NULL; + } + + void insertHelper(Node* ¤t, T value){ + if(current==NULL){ // We have reached bottom of the tree + // Base case + current = new Node(value); + }else{ + if(valuevalue){ + 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(value); // tree is empty + else{ + // the tree is not empty + insertHelper(root, value); + } + } + + bool hasHelper(Node* current, T value){ + bool f = false; + if(current!=NULL){ + if(current->value == value) return true; // match found + else{ + if(valuevalue){ // 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* current){ + if(current!=NULL){ + cout<value<<" "; + prefix(current->left); + prefix(current->right); + } + } + + void infix(Node* current){ + if(current!=NULL){ + infix(current->left); + cout<value<<" "; + infix(current->right); + } + } + + void postfix(Node* current){ + if(current!=NULL){ + postfix(current->left); + postfix(current->right); + cout<value<<" "; + } + } + + void display(int order=0){ + if(order==0) prefix(root); + else if(order==1) infix(root); + else if(order==2) postfix(root); + cout<* parent, Node* current, T value) { + //cout<value<value == value) { + + //if(current)cout<<"ff"<value<left == NULL || current->right == NULL) { + + Node* 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* 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"<value<left->value<value > value) + return deleteValueHelper(current, current->left, value); + return deleteValueHelper(current, current->right, value); + } + + + bool deleteValue(T value) { + Node* parent=NULL; + return deleteValueHelper(parent, root, value); + } +}; + + +int main(){ + BST firstTree; // We are creating the binary tree, it is empty + //BST tree2; + //BST tree3; + //BST tree4; + //BST tree5; + //BST> tree6; + //List> tree7; + int nums[] = {10, 7, 5, 6, 12, 11, 15}; + int c = 7; + + for(int i=0;i +using namespace std; + +int main() { + const bitset<12> mask(2730); + cout << "mask = " << mask << endl; + + bitset<12> x(8); + cout<> 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; + } +} diff --git a/SRC/Bitset.exe b/SRC/Bitset.exe new file mode 100755 index 0000000..f751e65 Binary files /dev/null and b/SRC/Bitset.exe differ diff --git a/SRC/Bitset.o b/SRC/Bitset.o new file mode 100755 index 0000000..e4887aa Binary files /dev/null and b/SRC/Bitset.o differ diff --git a/SRC/Count b/SRC/Count new file mode 100755 index 0000000..59e9f16 Binary files /dev/null and b/SRC/Count differ diff --git a/SRC/Count.cpp b/SRC/Count.cpp new file mode 100755 index 0000000..ba94380 --- /dev/null +++ b/SRC/Count.cpp @@ -0,0 +1,11 @@ +#include +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; +} diff --git a/SRC/Fibonicci b/SRC/Fibonicci new file mode 100755 index 0000000..5379c57 Binary files /dev/null and b/SRC/Fibonicci differ diff --git a/SRC/Fibonicci.cpp b/SRC/Fibonicci.cpp new file mode 100755 index 0000000..c6e079b --- /dev/null +++ b/SRC/Fibonicci.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main(){ + long long n; + int t=0; + cin>>n; + while(n!=0){ + t++; + long long count=0; + for(long long i=1;3*i+3<=n;i++){ + for(long long j=i+1;j*2+1<=n-i;j++){ + count++; + } + } + cout<<"Case #"<>n; + } +} diff --git a/SRC/Fibonicci.exe b/SRC/Fibonicci.exe new file mode 100755 index 0000000..5aff635 Binary files /dev/null and b/SRC/Fibonicci.exe differ diff --git a/SRC/Fibonicci.o b/SRC/Fibonicci.o new file mode 100755 index 0000000..8c4f838 Binary files /dev/null and b/SRC/Fibonicci.o differ diff --git a/SRC/HAsh b/SRC/HAsh new file mode 100755 index 0000000..9d7013d Binary files /dev/null and b/SRC/HAsh differ diff --git a/SRC/HAsh.cpp b/SRC/HAsh.cpp new file mode 100755 index 0000000..70cadc7 --- /dev/null +++ b/SRC/HAsh.cpp @@ -0,0 +1,8 @@ +#include +using namespace std; +int main() +{ + hash H; + cout << "foo -> " << H("foo") << endl; + cout << "bar -> " << H("bar") << endl; +} diff --git a/SRC/HAsh.exe b/SRC/HAsh.exe new file mode 100755 index 0000000..a69db31 Binary files /dev/null and b/SRC/HAsh.exe differ diff --git a/SRC/HAsh.o b/SRC/HAsh.o new file mode 100755 index 0000000..385d293 Binary files /dev/null and b/SRC/HAsh.o differ diff --git a/SRC/Implace_marge.cpp b/SRC/Implace_marge.cpp new file mode 100755 index 0000000..49a92ae --- /dev/null +++ b/SRC/Implace_marge.cpp @@ -0,0 +1,8 @@ +int main() +{ + int A[] = { 1, 3, 5, 7, 2, 4, 6, 8 }; + + inplace_merge(A, A + 4, A + 8); + copy(A, A + 8, ostream_iterator(cout, " ")); + // The output is "1 2 3 4 5 6 7 8". +} diff --git a/SRC/LeapYear.cpp b/SRC/LeapYear.cpp new file mode 100755 index 0000000..aa325e1 --- /dev/null +++ b/SRC/LeapYear.cpp @@ -0,0 +1,7 @@ +bool isALeapYear( int year ) +{ + /* Check if the year is divisible by 4 or + is divisible by 400 */ + return ((year % 4 == 0 && year % 100 != 0) || ( year % 400 == 0)); +} +- diff --git a/SRC/Seive_Prime b/SRC/Seive_Prime new file mode 100755 index 0000000..8bf6b1c Binary files /dev/null and b/SRC/Seive_Prime differ diff --git a/SRC/Seive_Prime.cpp b/SRC/Seive_Prime.cpp new file mode 100755 index 0000000..538daf7 --- /dev/null +++ b/SRC/Seive_Prime.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; + + +const int n=1000000; +bool prime[n+1]; + + +void primeGen() +{ + memset(prime,true,sizeof prime); + + for (int p=2; p*p<=n; p++) + { + if (prime[p]) + { + for (int i=p*2; i<=n; i += p) + prime[i] = false; + } + } +} + + +int main(){ + primeGen(); + prime[1]=0; + prime[0]=0; + int a,b; + while(cin>>a>>b){ + int bg=-1,en=-1,ma=-1,mb=-1,min=1000001,i; + for(i=a;i +using namespace std; + +inline bool lt_nocase(char c1, char c2) { return tolower(c1) < tolower(c2); } + +int main() +{ + int A1[] = {1, 3, 5, 7, 9, 11}; + int A2[] = {1, 1, 2, 3, 5, 8, 13}; + char A3[] = {'a', 'b', 'B', 'B', 'f', 'H'}; + char A4[] = {'A', 'B', 'b', 'C', 'D', 'F', 'F', 'h', 'h'}; + + const int N1 = sizeof(A1) / sizeof(int); + const int N2 = sizeof(A2) / sizeof(int); + const int N3 = sizeof(A3); + const int N4 = sizeof(A4); + + cout << "Union of A1 and A2: "; + int x[100]; + int *it= set_union(A1, A1 + N1, A2, A2 + N2,x); + for(int i=0;i(cout, " "), + lt_nocase); + cout << endl; +} diff --git a/SRC/Set_union.exe b/SRC/Set_union.exe new file mode 100755 index 0000000..10b1ee2 Binary files /dev/null and b/SRC/Set_union.exe differ diff --git a/SRC/Set_union.o b/SRC/Set_union.o new file mode 100755 index 0000000..24e4a13 Binary files /dev/null and b/SRC/Set_union.o differ diff --git a/SRC/Upper_bound b/SRC/Upper_bound new file mode 100755 index 0000000..6834792 Binary files /dev/null and b/SRC/Upper_bound differ diff --git a/SRC/Upper_bound.cpp b/SRC/Upper_bound.cpp new file mode 100755 index 0000000..4f1288e --- /dev/null +++ b/SRC/Upper_bound.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +int main() +{ + int A[] = { 1, 2, 3, 3, 3, 5, 8 }; + const int N = sizeof(A) / sizeof(int); + + for (int i = 1; i <= 10; ++i) { + int* p = lower_bound(A, A + N, i); + int* p = upper_bound(A, A + N, i); + cout << "Searching for " << i << ". "; + cout << "Result: index = " << p - A << ", "; + if (p != A + N) + cout << "A[" << p - A << "] == " << *p << endl; + else + cout << "which is off-the-end." << endl; + } +} + + + + + + + + + + + + + + + + + + + + + + + + +//google i talee 1536427 Abd.jalil.921 i taleem i taleem fb abd.jalil.165 abd&jalil921 `italeem diff --git a/SRC/Upper_bound.exe b/SRC/Upper_bound.exe new file mode 100755 index 0000000..c4e15d6 Binary files /dev/null and b/SRC/Upper_bound.exe differ diff --git a/SRC/Upper_bound.o b/SRC/Upper_bound.o new file mode 100755 index 0000000..eb692d4 Binary files /dev/null and b/SRC/Upper_bound.o differ diff --git a/SRC/adjacent_diff b/SRC/adjacent_diff new file mode 100755 index 0000000..5a0c2a7 Binary files /dev/null and b/SRC/adjacent_diff differ diff --git a/SRC/adjacent_diff.cpp b/SRC/adjacent_diff.cpp new file mode 100755 index 0000000..32beda2 --- /dev/null +++ b/SRC/adjacent_diff.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main() +{ + int A[] = {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}; + const int N = sizeof(A) / sizeof(int); + int B[N]; + int c[N]; + memset(c,0,sizeof c); + c[0]=1; + + cout << "A[]: "; + copy(A, A + N, B); + copy(B, B + N, ostream_iterator(cout," ")); + cout << endl; + + adjacent_difference(A, A + N, B); + cout << "Differences: "; + copy(B, B + N, ostream_iterator(cout, " ")); + cout << endl; + + cout << "Reconstruct: "; + partial_sum(B, B + N, ostream_iterator(cout, " ")); + cout << endl; + +cout << "Reconstruct: "; + partial_sum(c, c + N, ostream_iterator(cout, " ")); + cout << endl; +} + diff --git a/SRC/adjacent_diff.exe b/SRC/adjacent_diff.exe new file mode 100755 index 0000000..1ece515 Binary files /dev/null and b/SRC/adjacent_diff.exe differ diff --git a/SRC/adjacent_diff.o b/SRC/adjacent_diff.o new file mode 100755 index 0000000..42619e0 Binary files /dev/null and b/SRC/adjacent_diff.o differ diff --git a/SRC/adjacent_find b/SRC/adjacent_find new file mode 100755 index 0000000..518cf3b Binary files /dev/null and b/SRC/adjacent_find differ diff --git a/SRC/adjacent_find.cpp b/SRC/adjacent_find.cpp new file mode 100755 index 0000000..69ebb65 --- /dev/null +++ b/SRC/adjacent_find.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; + +int main(){ + int A[] = {1, 2, 3, 4, 6, 5, 7, 8}; +const int N = sizeof(A) / sizeof(int); + +const int* p = adjacent_find(A, A + N, greater()); + +cout << "Element " << p - A << " is out of order: " + << *p << " > " << *(p + 1) << "." << endl; +} diff --git a/SRC/adjacent_find.exe b/SRC/adjacent_find.exe new file mode 100755 index 0000000..a2ce6de Binary files /dev/null and b/SRC/adjacent_find.exe differ diff --git a/SRC/adjacent_find.o b/SRC/adjacent_find.o new file mode 100755 index 0000000..109cf78 Binary files /dev/null and b/SRC/adjacent_find.o differ diff --git a/SRC/advance_Iterator b/SRC/advance_Iterator new file mode 100755 index 0000000..d258c0b Binary files /dev/null and b/SRC/advance_Iterator differ diff --git a/SRC/advance_Iterator.cpp b/SRC/advance_Iterator.cpp new file mode 100755 index 0000000..93c5d2b --- /dev/null +++ b/SRC/advance_Iterator.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +int main(){ + list L; + L.push_back(0); + L.push_back(1); + + list::iterator i = L.begin(); + advance(i, 2); + assert(i == L.end()); + +} diff --git a/SRC/advance_Iterator.exe b/SRC/advance_Iterator.exe new file mode 100755 index 0000000..a6b28b3 Binary files /dev/null and b/SRC/advance_Iterator.exe differ diff --git a/SRC/advance_Iterator.o b/SRC/advance_Iterator.o new file mode 100755 index 0000000..7a4a83f Binary files /dev/null and b/SRC/advance_Iterator.o differ diff --git a/SRC/gcd.cpp b/SRC/gcd.cpp new file mode 100755 index 0000000..fae5f33 --- /dev/null +++ b/SRC/gcd.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; + +long long gcd(long long a, long long b){ + if(a==0 || b==0)return a+b; + return gcd(b, a % b); +} + +int main(){ + +} + diff --git a/SRC/includes.cpp b/SRC/includes.cpp new file mode 100755 index 0000000..8d70716 --- /dev/null +++ b/SRC/includes.cpp @@ -0,0 +1,22 @@ +int A1[] = { 1, 2, 3, 4, 5, 6, 7 }; +int A2[] = { 1, 4, 7 }; +int A3[] = { 2, 7, 9 }; +int A4[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; +int A5[] = { 1, 2, 13, 13 }; +int A6[] = { 1, 1, 3, 21 }; + +const int N1 = sizeof(A1) / sizeof(int); +const int N2 = sizeof(A2) / sizeof(int); +const int N3 = sizeof(A3) / sizeof(int); +const int N4 = sizeof(A4) / sizeof(int); +const int N5 = sizeof(A5) / sizeof(int); +const int N6 = sizeof(A6) / sizeof(int); + +cout << "A2 contained in A1: " + << (includes(A1, A1 + N1, A2, A2 + N2) ? "true" : "false") << endl; +cout << "A3 contained in A1: " + << (includes(A1, A1 + N2, A3, A3 + N3) ? "true" : "false") << endl; +cout << "A5 contained in A4: " + << (includes(A4, A4 + N4, A5, A5 + N5) ? "true" : "false") << endl; +cout << "A6 contained in A4: " + << (includes(A4, A4 + N4, A6, A6 + N6) ? "true" : "false") << endl; diff --git a/SRC/inner_product b/SRC/inner_product new file mode 100755 index 0000000..d6ee291 Binary files /dev/null and b/SRC/inner_product differ diff --git a/SRC/inner_product.cpp b/SRC/inner_product.cpp new file mode 100755 index 0000000..028808e --- /dev/null +++ b/SRC/inner_product.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main() +{ + int A1[] = {1, 2, 3}; + int A2[] = {4, 1, -2}; + const int N1 = sizeof(A1) / sizeof(int); + + cout << "The inner product of A1 and A2 is " + << inner_product(A1, A1 + N1, A2, 0) + << endl; +} diff --git a/SRC/inner_product.exe b/SRC/inner_product.exe new file mode 100755 index 0000000..b77c0a0 Binary files /dev/null and b/SRC/inner_product.exe differ diff --git a/SRC/inner_product.o b/SRC/inner_product.o new file mode 100755 index 0000000..3502a18 Binary files /dev/null and b/SRC/inner_product.o differ diff --git a/SRC/iota b/SRC/iota new file mode 100755 index 0000000..adf991a Binary files /dev/null and b/SRC/iota differ diff --git a/SRC/iota.cpp b/SRC/iota.cpp new file mode 100755 index 0000000..e6bbe86 --- /dev/null +++ b/SRC/iota.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + vector V(10); + + iota(V.begin(), V.end(), 7); + copy(V.begin(), V.end(), ostream_iterator(cout, " ")); + cout << endl; +} diff --git a/SRC/iota.exe b/SRC/iota.exe new file mode 100755 index 0000000..fa9f7cb Binary files /dev/null and b/SRC/iota.exe differ diff --git a/SRC/iota.o b/SRC/iota.o new file mode 100755 index 0000000..f521b89 Binary files /dev/null and b/SRC/iota.o differ diff --git a/SRC/itter_swap b/SRC/itter_swap new file mode 100755 index 0000000..cf08a4e Binary files /dev/null and b/SRC/itter_swap differ diff --git a/SRC/itter_swap.cpp b/SRC/itter_swap.cpp new file mode 100755 index 0000000..fc7943d --- /dev/null +++ b/SRC/itter_swap.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; + +int main(){ + int x = 1; +int y = 2; +//assert(x == 2 && y == 2); +iter_swap(&x, &y); +cout< +using namespace std; + +long long ncr(long long n,long long r){ + long long ans=1; + for(int i=1;i<=r;i++){ + ans*=(n-r+i); + ans/=i; + } + return ans; +} diff --git a/SRC/next_permutation b/SRC/next_permutation new file mode 100755 index 0000000..3d0e8ac Binary files /dev/null and b/SRC/next_permutation differ diff --git a/SRC/next_permutation.cpp b/SRC/next_permutation.cpp new file mode 100755 index 0000000..ea83128 --- /dev/null +++ b/SRC/next_permutation.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() { + + int p[10], N = 5; for (int i = 0; i < N; i++) p[i] = i; + //char ex[10]="ASH"; + //sort(ex,ex+3); + do { + for (int i = 0; i < N; i++) + printf("%c ", 'A' + p[i]); + printf("\n"); + //cout< +using namespace std; + +const int ROW=6; +const int COL=6; +const int offSet[]={-1,0,1}; + +bool neighborExist(int ex[][COL],int i,int j){ + if(i>=0 && i=0 && j +using namespace std; + +int main() { + + //double pi=2*acos(0.0); + double pi=acos(-1); + printf("%13.*lf\n",10,pi); +} + \ No newline at end of file diff --git a/SRC/pi.exe b/SRC/pi.exe new file mode 100755 index 0000000..2b8f402 Binary files /dev/null and b/SRC/pi.exe differ diff --git a/SRC/pi.o b/SRC/pi.o new file mode 100755 index 0000000..b58e401 Binary files /dev/null and b/SRC/pi.o differ diff --git a/SRC/set_intersection.cpp b/SRC/set_intersection.cpp new file mode 100755 index 0000000..d1dd6bc --- /dev/null +++ b/SRC/set_intersection.cpp @@ -0,0 +1,24 @@ +inline bool lt_nocase(char c1, char c2) { return tolower(c1) < tolower(c2); } + +int main() +{ + int A1[] = {1, 3, 5, 7, 9, 11}; + int A2[] = {1, 1, 2, 3, 5, 8, 13}; + char A3[] = {'a', 'b', 'b', 'B', 'B', 'f', 'h', 'H'}; + char A4[] = {'A', 'B', 'B', 'C', 'D', 'F', 'F', 'H' }; + + const int N1 = sizeof(A1) / sizeof(int); + const int N2 = sizeof(A2) / sizeof(int); + const int N3 = sizeof(A3); + const int N4 = sizeof(A4); + + cout << "Intersection of A1 and A2: "; + set_intersection(A1, A1 + N1, A2, A2 + N2, + ostream_iterator(cout, " ")); + cout << endl + << "Intersection of A3 and A4: "; + set_intersection(A3, A3 + N3, A4, A4 + N4, + ostream_iterator(cout, " "), + lt_nocase); + cout << endl; +} diff --git a/SRC/simpleSumming b/SRC/simpleSumming new file mode 100755 index 0000000..7745947 Binary files /dev/null and b/SRC/simpleSumming differ diff --git a/SRC/simpleSumming.cpp b/SRC/simpleSumming.cpp new file mode 100755 index 0000000..5747929 --- /dev/null +++ b/SRC/simpleSumming.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() +{ + int A[] = {1, 2, 3, 4, 5}; + const int N = sizeof(A) / sizeof(int); + + cout << "The sum of all elements in A is " + << accumulate(A, A + N, 0) + << endl; + + cout << "The product of all elements in A is " + << accumulate(A, A + N, 1,multiplies()) + << endl; +} diff --git a/SRC/simpleSumming.exe b/SRC/simpleSumming.exe new file mode 100755 index 0000000..7928446 Binary files /dev/null and b/SRC/simpleSumming.exe differ diff --git a/SRC/simpleSumming.o b/SRC/simpleSumming.o new file mode 100755 index 0000000..f6e3197 Binary files /dev/null and b/SRC/simpleSumming.o differ diff --git a/SRC/sortCOmaparison_try.cpp b/SRC/sortCOmaparison_try.cpp new file mode 100755 index 0000000..2af32b3 --- /dev/null +++ b/SRC/sortCOmaparison_try.cpp @@ -0,0 +1,63 @@ +#include + +using namespace std; + +#define eps 0.001 + +struct Frog{ + double h,w,j; + int i; + Frog(){} + Frog(double _h, double _w, double _j, int _i ){ + h=_h; w=_w; j=_j; i=_i; + } + /*bool operator()(const Frog& a, const Frog& b){ + if(a.h < b.h) + return false; + else if(abs(a.h-b.h)b.w) + return false; + else if(abs(a.w-b.w)b.w) + return false; + else if(abs(a.w-b.w)>n; + vector ex; + for(int i=0;i>h>>w>>j; + ex.push_back(Frog(h,w,j,i+1)); + } + sort(ex.begin(),ex.end(),compare); + for(int i=0;i + +using namespace std; + +#define eps 0.001 + +// This is the custom data container for this solution +struct Frog{ + double h,w,l; // h->height, w->weight, l->length of jump + int i; // i-> position in the original list + Frog(){} // Empty Constructor, it is needed for sorting using sort function + Frog(double _h, double _w, double _l, int _i){ h = _h; w = _w; l = _l; i = _i;} // Constructor for initializing + // The following function defines the nature of the operator overloading + // In this case the operator is the comparison function, defined by "()" symbol + bool operator()(const Frog& a, const Frog& b){ + // The follwing conditions decides whether 'a' should go before 'b' or not + if(a.hb.w){ + return false; + }else if(abs(a.w-b.w) frogs; + double h,w,l; + for(int i=0;i +using namespace std; +/* +int compare (const void * a, const void * b) +{ + return ( *(int*)a - *(int*)b ); +} +*/ +int compare( const void *aa, const void *bb) +{ + const int col=1;//will sort base on third element + int *a=(int *)aa; + int *b=(int *)bb; + if (a[col]a[col] for descending order + return -1; + else if (a[col]==b[col]) + return 0; + else + return 1; + +} + +int cmp( const void * aa, const void * bb) +{ + int *a=(int * )aa; + int *b=(int *)bb; + const int col=0;//will sort base on third element + cout<b[col])//a[col]>a[col] for descending order + return 1; + else if (a[col]==b[col]) + return 0; + else + return -1; + +} +int main() +{ + const int row=3,col=5; + int ex[row][col]={2,5,1,4,7,7,2,5,3,4,4,41,32,5,3}; + for(int i=0;i<3;i++){ + for(int j=0;j<5;j++) + cout< +using namespace std; + +int main(){ + int A[] = {1, 4, 2, 8, 5, 7}; + const int N = sizeof(A) / sizeof(int); + sort(A, A + N); + string ex[]={"sa","fes","fef"}; + copy(ex,ex+3,ostream_iterator(cout," ")); + //copy(ex, ex + 3, ostream_iterator(cout, " ")); +} diff --git a/SRC/special_Cout.exe b/SRC/special_Cout.exe new file mode 100755 index 0000000..158d8e6 Binary files /dev/null and b/SRC/special_Cout.exe differ diff --git a/SRC/special_Cout.o b/SRC/special_Cout.o new file mode 100755 index 0000000..527573c Binary files /dev/null and b/SRC/special_Cout.o differ diff --git a/SRC/subset b/SRC/subset new file mode 100755 index 0000000..e8f8c1d Binary files /dev/null and b/SRC/subset differ diff --git a/SRC/subset.cpp b/SRC/subset.cpp new file mode 100755 index 0000000..37fbe16 --- /dev/null +++ b/SRC/subset.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +const int n=3; +int main(){ + + int ex[n]; + for(int i=0;i + +using namespace std; + +int main() { + + int a,b,x; + cin>>a>>b; + x=a+b; + cout<<"X = "< + +using namespace std; + +int main(){ + + string ex="ashik"; + string fx=string(ex.rbegin(),ex.rend()); + cout<