-
Notifications
You must be signed in to change notification settings - Fork 0
/
1103.cpp
36 lines (30 loc) · 797 Bytes
/
1103.cpp
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
35
36
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> distributeCandies(int candies, int num_people) {
vector<int> res(num_people, 0);
int index = 0;
int candy = 1;
while (candies) {
res[index % num_people] += min(candy, candies);
candies -= min(candy, candies);
index++;
candy++;
}
return res;
}
};
int main() {
Solution solution;
int candies = 7;
int num_people = 4;
std::vector<int> result = solution.distributeCandies(candies, num_people);
std::cout << "Candies distribution: ";
for (int i = 0; i < result.size(); i++) {
std::cout << result[i] << " ";
}
std::cout << std::endl;
return 0;
}