C/C++ :: How To Find All Possible Combinations In 2D Array With Given Sum

Feb 26, 2015

How to find all possible combinations of coordinates on a 2d grid with a given sum. The sum is not fixed!

E.g. N=nxm=25 thats our grid.

The sum=distance between points on a grid.

For two points distance=|(x1-x2)+(y1-y2)| point A(X1,Y1) B(X1,Y1)

My interest is to know how to find the combinations of coordinates with a given sum, it doesn't matter how many points are there.

If i enter the sum e.g sum=7 and the program has to show all possible combinations which gives the sum of 7 the number of point does not play in row they might be two or maybe more.

View 4 Replies


ADVERTISEMENT

C :: Combinations - Putting Strings Into Array From A File

Apr 4, 2014

The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.

Basically the input will look like this: 2 3 2 taco burrito nacho

And the output looks like this: burritos nachos nacho taco burrito taco

This is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(void){
int N, T, K;
char menu[N][20];

[Code] .....

What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?

View 4 Replies View Related

C/C++ :: Generate Combinations Of Numbers From 1 To 25 In 15 Numbers Array?

Sep 21, 2014

The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:

1 3 4 5 6 8 10 13 14 16 17 18 19 20 25

3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________

Count = 8, in this case..

I think it's not very difficult to do, but i just can't see how to do it.

#include <iostream>
#include <vector>
#include <numeric>

[Code]....

View 3 Replies View Related

C++ :: Algorithm For All Possible Combinations?

Mar 7, 2013

A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).

Example: Desired numerical combinations from integers 1 to 3:

At Length 1:

1, 2, 3

At Length 2:

11, 12, 13, 21, 22, 23, 31, 32, 33

At Length 3:

111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333

And so on until the nth length (in my case a length of 12).

First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.

Here are a few of my attempts:

Attempt 1:

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

[Code]....

I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.

Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.

I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.

View 14 Replies View Related

C++ :: How To Output All Possible Binary Combinations

Mar 4, 2014

I need to create a function that outputs all possible binary combinations. I'm really stumped on this. I have to do it with nested loops, and am not sure how to go about it. Below is what I tried so far.

The output should look like this:

00000000
00000001
00000010
00000011
00000100
...
11111110
11111111

Code:

void outputBinary(){
int a[2][2][2][2][2][2][2][2];
for (int i = 0; i < 2; i++){
for (int j = 0; j < 2; j++){

[Code] .....

View 2 Replies View Related

C++ :: Print All Combinations Data

Nov 27, 2013

I wanted to create a 5, 3 combinations. i know how to calculate to get the number of combinations 5 3 would have (which is ten), but it seem it's a bit harder for me to print those data ...

View 2 Replies View Related

C :: Printing All Combinations Of A String Loop

Jan 25, 2013

Code:

#include<stdio.h>
#include<string.h>
#define a 15

[Code]....

I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words

View 4 Replies View Related

C++ :: Program For Printing All The Combinations Of A String

Feb 17, 2013

I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.

"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010

#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)

[Code] .....

View 1 Replies View Related

C++ :: All Possible Combinations For 4 Digits From A 5 Digit Number

Jun 23, 2014

How to get all the possible combinations for 4 digits from a 5 digit number. I need a pair that has both 5 digits and four digits. their sum must be equal to a five digit user input. i.e.

user input : 14690
output:
14690 has pairs 12345 + 2345
2345 came from 12345
lets say that x = 12345 and y =2345
besides y == x%10000

other formula can i have since if i use % and / i will have a lot of declarations....

View 2 Replies View Related

C++ :: Generating All Possible Combinations Of Vector Elements

Feb 14, 2013

I have an integer vector of size "n".

e.g.
std::vector<int> vec;
vec.pushback(0);
vec.pushback(1);
vec.pushback(2);
vec.pushback(3);

Now I want to generate all possible combinations of size = {0, 1, 2, ... , n}.

{0, 1, 3} is not equal to {3, 1, 0} or {1, 0, 3} or {3, 0, 1}

View 7 Replies View Related

C++ :: How To Calculate And Apply All Char Combinations

Jan 12, 2015

how to write a password cracking program that will try all possible char combinations for just two chars (without duplicating any combination guesses). Obviously, there would only be 4 possible truth table combinations for two boolean values, but how would a person calculate the number of all possible combinations for two values with 70 different possible chars?

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
/*

Boolean Truth Table for two values:

p q
-----
T T
T F
F T
F F

Note that there are 70 chars in all specified above.

It will require much more than a simple truth table to try every possible char combination (especially if the password to be cracked is 2 or more chars). Using this guy's code: [URL] ..... as a starting point, I'm writing a program that will crack a password with a length of just 2 chars.

*/
int stringLength = 2;
char genRandom() {
return alphanum[rand() % stringLength];
}
int main() {
std::string password = "Sp";
srand(time(0));
std::string Str;

[code]....

View 19 Replies View Related

C :: Print All Combinations Of Numbers That Can Compose A Given Number

Mar 6, 2015

Coding for- To print all combinations of numbers that can compose a given number..

View 3 Replies View Related

C :: Accept Password From Standard Input And Goes Through All Possible Combinations Until It Matched

Dec 24, 2014

I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?

View 1 Replies View Related

C :: How To Find Maximum Value Of Array

Oct 29, 2014

Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.

In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code].....

View 10 Replies View Related

C++ :: How To Find First Element In Array

Oct 7, 2013

Lets assume, I use array of 100 the i input 50 element and now i want to find which one is first in array... without using pointer ...

View 2 Replies View Related

C++ :: Find Median Of Array?

Jul 4, 2013

I am trying to find the median of an array in c++.

This is the array that I would like to find the median for.

scores[14] = {62,70,98,71,81,99,74,80,73,88,73,72,95,71};

View 5 Replies View Related

C++ :: How To Find Mode In Array

Feb 6, 2014

How do you find a mode in array? This is what i got so far. I put this after i sort the array

for (int index = 0; index < size2; index ++) {
//count[mode[index] - 1]++;
if (mode[index] == mode[index + 1]) // compare the first to sec array {
again++;
cout <<"This is number " << again << endl;
}
}

View 1 Replies View Related

C++ :: Find Highest Value Of Array

Nov 4, 2013

I am currently trying to make a simple method for an array that would find the highest value. here is currently what i got, but do not know what to change to make it correct.

double FindMax(double stock[], int size){
int size = stock.length();
int max = stock[0];

for(int i = 1; i < size; i++){
if (stock[i] > max)
{max = stock{i};}
}
return max;

View 3 Replies View Related

C++ :: Find GCD Of Array Of Numbers

Aug 25, 2013

I wrote this GCD function to find gcd of an array of numbers . Here is the code:

long long GCD(long long min,int loc,long long b[]) {
for (long long i=min;i>0;i--) {
bool p=0;
for (long long x=0;x<loc;x++) {
if (b[x]%i!=0)

[Code] ....

Its returning wrong answers. When i tried 6 14 it returns 6

View 6 Replies View Related

C/C++ :: How To Find A Specific Value In Array

Mar 16, 2015

im having trouble with a function im writing. Its supposed to find the minimum value in an array and return the location of that value heres what i have so far :

int findLowest (int numb []) {
// findLow will hold the subscript of the lowest value in the array
int findLow = numb[0];
int x;
for (x = 0; x < 5; x++){
if (numb[x] < findLow)
findLow = x;
}
return findLow;
}

View 3 Replies View Related

C :: Find The Length Of Char Array

Sep 25, 2014

I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.

View 2 Replies View Related

C :: Find The Value Occurs Most In 8 Integer Array

Jan 30, 2015

I want to find the value occurs most in an 8 integer array. Here is the code that I have. It does compile, but has not been tested.

Code:
int POLL (int *RANGE_ARRAY) {

int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int j = 0;
intk;

[Code] .....

Does this look right or is there a better way of doing this?

View 12 Replies View Related

C :: Find Prime Numbers - How To Use Bit Array

Aug 19, 2013

I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#include <ctype.h>
#include <stdint.h>

//function to set all non-primes to 0
void *zero_multiples(void *threadid);

[Code] .....

View 4 Replies View Related

C :: How To Find Duplicates In Array Of Structures

Jul 21, 2014

I have an array of structures with structure def that looks like.

Code:
struct {
char * name;
char * school;
int age;
}

there are multiple people with same name but different ages so i want to list them like.

Name.
age 1
age 2 and so on

The array is sorted by name already.

View 3 Replies View Related

C++ :: Find First 10 And Last 10 Words Of String Array

Jan 26, 2015

I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.

#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int tokenize(string sentence, string tokenizedWords[]);

[code]....

View 2 Replies View Related

C++ :: Find All Unique Triplet In Given Array With Sum Zero

Feb 26, 2015

I got all unique triplet from below code but I want to reduce its time complexity. It consist three for loop. So my question is, Is it possible to do in minimum loop that it decrease its time complexity. code will be execute in minimum time.

#include <cstdlib>
#include<iostream>
using namespace std;
void Triplet(int[], int, int);
void Triplet(int array[], int n, int sum) {

[Code] .....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved