-
Birthday Chocolate해커랭크(HackerRank) 2018. 8. 19. 17:37반응형
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
123456789101112131415161718192021222324252627282930313233343536#include <bits/stdc++.h>using namespace std;int solve(int n, vector < int > s, int d, int m){// Complete this functionint sol = 0;for(int i = 0; i < n-m+1; i ++) {int dist = i + m;int cand = 0 ;for(int j = i; j <dist; j++) {cand = cand + s[j];}if (cand == d) {sol++;}}return sol;}int main() {int n;cin >> n;vector<int> s(n);for(int s_i = 0; s_i < n; s_i++){cin >> s[s_i];}int d;int m;cin >> d >> m;int result = solve(n, s, d, m);cout << result << endl;return 0;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Day 0: Mean, Median, and Mode (0) 2018.08.19 Breaking the Records (0) 2018.08.19 Divisible Sum Pairs (0) 2018.08.19 Migratory Birds (0) 2018.08.19 Bon Appétit (0) 2018.08.19