-
Sock Merchant해커랭크(HackerRank) 2018. 8. 19. 17:34반응형
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
123456789101112131415161718192021222324252627282930313233343536373839404142#include <bits/stdc++.h>using namespace std;int sockMerchant(int n, vector <int> ar) {// Complete this functionmap<int, int> m;for(int i = 0; i < n; i++) {//cout << ar[i] << endl;m[ar[i]]++;}map<int, int>::iterator iter;int sol = 0;for(iter = m.begin(); iter != m.end(); ++iter) {//cout << iter->first << " " << iter->second << endl;int value = iter->second ;if(value >= 2) {int cand = iter->second / 2;sol = sol + cand;}}return sol;}int main() {int n;cin >> n;vector<int> ar(n);for(int ar_i = 0; ar_i < n; ar_i++){cin >> ar[ar_i];}int result = sockMerchant(n, ar);cout << result << endl;return 0;}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Migratory Birds (0) 2018.08.19 Bon Appétit (0) 2018.08.19 Cats and a Mouse (0) 2018.08.19 Picking Numbers (0) 2018.08.19 Designer PDF Viewer (0) 2018.08.19