rengetsu

HackerRank_BirthdayChocolate

Jun 19th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. //Birthday Chocolate
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n, s[1000], d, m, sum=0, ats=0;
  7.     cin >> n;
  8.     for(int i=0;i<n;i++)
  9.     {
  10.         cin >> s[i];
  11.     }
  12.     cin >> d >> m;
  13.     for(int y=0;y<n;y++)
  14.     {
  15.         sum=0;
  16.         sum+=s[y];
  17.         for(int j=y+1;j<m;j++)
  18.         {
  19.             sum+=s[j];
  20.         }
  21.         m++;
  22.         if(sum==d)
  23.         {
  24.         ats++;
  25.         }
  26.     }
  27.     cout << ats << endl;
  28.     return 0;
  29. }
Add Comment
Please, Sign In to add comment