Notice
Recent Posts
Recent Comments
-
[프로그래머스] 레벨 2 - 위장 본문
<map> 컨테이너를 이용해 의상 종류별로 몇 개의 요소가 있는지 확인한 뒤,
그 종류를 사용하지 않은 경우를 + 1한 것들을 모두 곱한다.
마지막으로 모두 사용하지 않은 경우는 없으므로 1을 뺀 것이 답이 된다.
map 컨테이너에 key값이 아직 존재하지 않더라도 map[key]++;하면 자동으로 생성되는 것을 알았다.
순회방식은 iterator을 사용해 해준다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
map<string, int> m;
for (int i = 0; i<clothes.size(); i++){
string type = clothes[i][1];
m[type]++;
}
int temp = 1;
for (map<string, int>::iterator it = m.begin(); it != m.end(); it++){
temp *= (it->second+1);
}
return temp-1;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-4. 프로그래머스' 카테고리의 다른 글
[프로그래머스] 레벨 2 - 전화번호 목록 (0) | 2020.02.07 |
---|---|
[프로그래머스] 레벨 2 - 숫자 야구 (0) | 2020.02.06 |
[프로그래머스] 레벨 2 - 큰 수 만들기 (0) | 2020.02.06 |
[프로그래머스] 레벨 2 - 더 맵게 (0) | 2020.02.06 |
[프로그래머스] 레벨 2 - 가장 큰 수 (0) | 2020.02.04 |
Comments