A program is a set of all subsets of this part of the show. Users can enter a number., For example, if n = 2 the output looks like this:
{} {1} {2} {1,2} or for n=3 we have: {} {1} {2} {3} {1,2} {1,3} {2,3} {1,2,3}
meantime this program should be solved with tow way. recursive function and Non-recursive.Can also be used in solving the problem of bitwise operations.
To check if a set B is a subset of A or not. Which data structure to be used to store set A for quicker response(linked list/hash map)? What if I want to check intersection also?
The problem is that you have a set of numbers and you need to divide that set into two subsets where the difference between the sums of the subset is minimal.
Example: a set of numbers {1,5,9,3,8}, now the solution is two subsets, one subset with elements {9,3} and the other {8,5,1} the sum of the first one is 13 and the sum of the second is 13 so the difference between the sums is 0. The result shows the difference between the sums.
Another example: a set of numbers where the difference between the subsets cannot be zero, {9 51 308 107 27 91 62 176 28 6}, the minimal difference between the two subsets is 2.
I want to know how the function finds the two subsets, it works great because I've tested it for up to 300 inputs which sum adds up to 100,000.
Code: #include <iostream> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <limits.h> using namespace std; int BalancedPartition ( int a[] , int n ) {
I'm trying to get unique elements from a set but it prints for each item all the rest, for example if i have 3 items in a set it will print 6 instead of 3. I use this code:
for (set<string>::iterator i = mails.begin(); i != mails.end(); ++i) { cout << *i << endl; }
Is there any way to print just the unique items from a set ?
84484-37.96-Castor, Kathy 39050-69.68-Chandler, Ben 26183-70.84-Costello, Jerry
I have successfully read each element the id, grade and name into 3 separate array. Now i need to add a new student with an id and grade
How do i do this?
This is what I have.
int addStudent( int Iarray[], double dArray[], string sArray[], int newID, double newGrade, string newName, int size ) { char ready; int index; cout << endl; cout << "Enter new student ID number : ";
I have a question regarding the elements of an array. Suppose I have a 3 by 3 string array (char x[3][4] ) , and I initialize all the elements to x's , the array would then look like this :
xxx xxx xxx
I'm curious if there will be a value if I try to access and element outside the array. As I have to write a code to determine if I have reached the end of an array. The only way I can think of is to border the entire array with o's , making it look like this :
As far as I'm understand we have only access to .h files of elements of STL. So other words in MS VC 2010 we haven't opportunity to see exact implementation of elements of STL. Where I can find implementation of STL elements or substitute algorithm that do the same thinks like stack from stl
I'm writing a program with a class containing a private std::vector<bool>. I chose bool because the vector represents a 2D array (think grid) and I only need 2 states per cell. I kept it one-dimensional as this hardly complicates things.
My problem is that I don't know how to initialize the vector, i.e. fill it with 0's.
The grid's resolution is not known at compile time, so I imagine I have to set the size (and content) of the vector in the class constructor.
Here's what I have tried among several things:
Code: World::World(const u_short worldsize) { grid.reserve(worldsize * worldsize); // grid is the private vector; square dimensions. std::fill(grid.begin(), grid.end(), 0); std::cout << grid.size(); } The output is 0. Only std::vector::push_back seems to have an effect on size(), but judging by its description, it doesn't look like the right candidate to populate a vector with zeros. Correct me if I'm wrong.
Frankly I expected line 3 to set the vector's size.
Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the number of elements in thearray . The function reverses the elements of the array . The function does not return a value .
Code: void reverse(int a[], int num) { for ( int i=0; i <= num/2 ; i++){ int temp = a[i]; a[i] = a[num-i-1]; a[num-i-1] = temp; } }
This is supposed to be the answer but I'm not quite sure why this is. I understand everything up until the actual loop. For one, shouldn't "int i" be declared outside the loop (I thought perhaps this was an error in the solutions)?
The main thing that I do not understand is the conditional statement.
Code: i<=num/2;
I don't understand why the "num/2" is necessary here. Also I can't really remember but is there a command that actually reverses an array?
I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:
Code:
typedef struct gg{ int id; int value; }
[code]....
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?
My goal is to copy only the elements of string 2 that are equal to string 1 into a new string. I tested this idea with an array of integers and it worked, but didn't work for the strings.
Code:
#include<stdio.h> main() { int scan1; char arr1[40] ; char arr2[40] ; char arr3[40] = {'_',.....,'_'}; /*for sake of brevity with post*/ }
Why is it that in the STL it is standard to indicate a sequence of elements in a container by a begin iterator that points to the first element and an end iterator that points to one past the last element?
If I have 2 arrays, say array1 = {2, 2, 4, 5, 6} which has sorted array elements and array2 = {4, 2, 6, 2, 5} that has same elements as array1 but not in sorted condition. How can I compare that both arrays have same elements. I have written the following code which works in all conditions except when array1 has two same elements and array2 has all different elements.
counter=0; for (i=0; i<5; i++) { for (int j=0; j<5; j++) if (array2[i] == array1[j]) { counter++; array1[j]=0;
I am trying to write a program that reverses the elements of an array by using an function 'myreverse'. The function should reverse original array and return nothing.
In my program, the function 'myreverse' is not getting invoked and the original array is being displayed as it is.
#include <iostream> using namespace std; void myreverse(int arr[],int n) { int *p=&arr[n-1]; int temp; for(int i=0;i<n;++i)
I'm having trouble getting my array to add its values together. I have a similar program running fine with the exact same equation. I am not so naive as to believe that this means it should run with every program but I'm at a loss as to what to do.
#include <iostream> #include <iomanip> using namespace std;
I was wondering if there was some sort of C++ equivalent for the IDL FIX function. For example, say I want to find all the elements of FLOAT ARRAY1[] that are greater than NUM1 and convert them to INT ARRAY2[].
The problem I have with writing this code myself is not knowing how many elements are going to be greater than NUM1, so I don't know how to initialize ARRAY2[?].
something in this part is making it go wrong, it displayes the original array fine but when it tries to shift it it goes haywire. EDIT: also how would i add elements onto the array?