-
Divisible Sum Pairs해커랭크(HackerRank) 2018. 8. 19. 17:36반응형
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
1234567891011121314151617181920212223242526272829303132333435#include <bits/stdc++.h>using namespace std;int divisibleSumPairs(int n, int k, vector <int> ar) {// Complete this functionconst int size = ar.size();int sol = 0;for(int i =0; i<size; i++) {for(int j=i+1; j<size; j++) {int cand = ar[i] + ar[j];// can divisible by kif (cand % k == 0) {sol++;}}}return sol;}int main() {int n;int k;cin >> n >> k;vector<int> ar(n);for(int ar_i = 0; ar_i < n; ar_i++){cin >> ar[ar_i];}int result = divisibleSumPairs(n, k, ar);cout << result << endl;return 0;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Breaking the Records (0) 2018.08.19 Birthday Chocolate (0) 2018.08.19 Migratory Birds (0) 2018.08.19 Bon Appétit (0) 2018.08.19 Sock Merchant (0) 2018.08.19