i need help with the logic of this function, the 'priority' problem from talentbuddy.co

Hey guys, first i would like to state thank you for your help in advance.

I'll just copy and paste the problem here and write my thought underneath

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Priority
Our website receives visitors from 3 locations and the number of unique visitors from each of them is represented by three integers a, b and c.
Considering our servers cannot serve more than N visitors, which is always less than the total number of users from all three locations
Your task is to
write a function that prints to the standard output (stdout) the number of unique possible configurations (as, bs, cs) which can be used to serve exactly N visitors
as represents the number of users from location a we choose to serve
bs represents the number of users from location b we choose to serve
cs represents the number of users from location c we choose to serve
Note that your function will receive the following arguments:
a
which is an integer representing the number of users from location a
b
which is an integer representing the number of users from location b
c
which is an integer representing the number of users from location c
n
which is an integer representing the number of users our servers can serve
Data constraints
the values for a, b, c will be in the [0 .. 100] range
n will always be smaller than the sum of a, b, and c
Example
Input	Output
a: 1
b: 1
c: 1
n: 2
3
a: 2
b: 2
c: 2
n: 2
6
Explanation
The possible configurations for the second example are: (1, 1, 0), (1, 0, 1), (0, 1, 1), (2, 0, 0), (0, 2, 0), (0, 0, 2).


Quite frankly, i have no idea where to start. I have a feeling ill be using an array with a loop, but i can't quite figure out how to tackle this.
At the risk of sounding odd, i would like to "talk" this out with someone on here if that makes sense. As in, i dont want just the answer :P
Ok, so, it took me a few times reading this, but from what I understand is that you need to display all the different permutations that can occur for the three servers. a, b, and c can all have up to 100 customers. n, which is the number of customers the server can handle, will always be 300, or less. Your job is to determine how many different permutations exist where the total number of customers served between a, b, and c will equal N.

A quick example:
a: 50
b: 25
c: 70
n: 120


From that example, two of the possible permutations are {50, 0, 70} and {25, 25, 70}. Your job is to figure out how many different ways that's possible. I suggest using for loops to iterate over the unique customers, and a for loop to check that the total of customers equals the number that can be supplied with the server.

If you need help from there, let me know.

void count_configurations(int a, int b, int c, int n) {

int counter = 0;
for( int a1 = a; a1 != 0; a1--){
for(int b1 = b; b1 != 0 ; b1--){
for(int c1 = c; c1 != 0 ; c--){
if( n == c1 + b1 + a1){
counter++;
}
}
}
}

cout << counter;
`
}
Topic archived. No new replies allowed.