-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirthdayChoclate.cpp
More file actions
42 lines (39 loc) · 1.05 KB
/
BirthdayChoclate.cpp
File metadata and controls
42 lines (39 loc) · 1.05 KB
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
37
38
39
40
41
42
/*Lily has a chocolate bar that she wants to share it with Ron for his birthday.
Each of the squares has an integer on it. She decides to share a contiguous segment
of the bar selected such that the length of the segment matches Ron's birth month
and the sum of the integers on the squares is equal to his birth day.
You must determine how many ways she can divide the chocolate.
*/
#include <bits/stdc++.h>
#include<stdlib.h>
using namespace std;
int getWays(int squares_size, int* squares, int d, int m){
int j,k=1,t=m,sum=0,count=0;
for(int i=0;i<squares_size;i++){
sum=squares[i];
for(j=k;j<t;j++){
sum+=squares[j];
}
if(sum==d){
count++;
}
k++;
t++;
}
return count;
}
int main() {
int n;
cin>>n;
//int *s = malloc(sizeof(int) * n);
int *s = (int*)malloc(n * sizeof(int));
for(int s_i = 0; s_i < n; s_i++){
cin>>s[s_i];
}
int d;
int m;
cin>>d>>m;
int result = getWays(n, s, d, m);
cout<<result;
return 0;
}