-
Picking Numbers해커랭크(HackerRank) 2018. 8. 19. 17:32반응형
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
12345678910111213141516171819202122232425262728293031323334353637383940#include <bits/stdc++.h>using namespace std;int pickingNumbers(vector <int> a) {// Complete this functionsort(a.begin(), a.end());const int size = a.size();int solution = 0;for(int i=0; i<size; i++) {int cand = 0;for(int j=i+1; j<size; j++) {int cand2 = abs(a[i] - a[j]);if(cand2 == 1 || cand2 == 0)cand++;elsebreak;}if(solution < cand) {solution = cand;}}return solution+1;}int main() {int n;cin >> n;vector<int> a(n);for(int a_i = 0; a_i < n; a_i++){cin >> a[a_i];}int result = pickingNumbers(a);cout << result << endl;return 0;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Sock Merchant (0) 2018.08.19 Cats and a Mouse (0) 2018.08.19 Designer PDF Viewer (0) 2018.08.19 Utopian Tree (0) 2018.08.19 Beautiful Days at the Movies (0) 2018.08.19