Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- transform.position
- 유니티
- 백준 11726번 C++
- 백준
- rigidbody.position
- TOPCIT 문제 유형
- 백준 2193번 c++
- long int 의 차이
- 배열 stack overflow
- 백준 10844번 c++
- rigidbody.Moveposition
- 1699번
- bfs
- c++
- 백준 2225번 c++
- 2644번
- UML Diagram 정리
- 백준 10799번 c++
- 프로그래머스 가장 큰 수 C++
- 코드
- 백준 17299번 c++
- 유니티 꿀팁
- 로블록스 script local script 차이
- 유니티 LTS
- 풀이
- 플레이어 이동
- 차이
- 유니티 Rigidbody 이동
- 프로그래머스 단체사진 찍기 C++
- TOPCIT 후기
Archives
- Today
- Total
Kiki Devlog
[프로그래머스][Lv 2] 위장 (stl map, 포인터의 화살표 연산자) 본문
728x90
map 쓰는 법을 까먹어서 다시 풀어본 문제. 풀면서 겸사겸사 포인터 화살표 연산자도 정리해 둠! 미묘하게 이전에 짠 코드보다 발전했음을 알 수 있다(●'◡'●)
문제: 코딩테스트 연습 - 위장 | 프로그래머스 (programmers.co.kr)
코딩테스트 연습 - 위장
programmers.co.kr
내 코드
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 0;
map<string,vector<string>> m;
map<string,vector<string>> ::iterator iter;
for(int i = 0;i<clothes.size();i++){
m[clothes[i][1]].push_back(clothes[i][0]);
}
int ans = 1;
for(iter = m.begin();iter !=m.end();iter++){
ans = ans * (iter->second.size()+1);
// 위와 같은 코드. ans = ans * ((*iter).second.size()+1);
}
answer = ans-1;//아무것도 안입는 상황 제외
return answer;
}
이전 내 코드 (언제 푼지 모르는데 1년은 넘음)
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
map<string,int> m;
map<string,int> :: iterator iter;
for(int i = 0; i<clothes.size();i++){
iter = m.find(clothes[i][1]);
if(iter!=m.end()){
(iter->second)++;
}
else{
m.insert(pair<string,int>(clothes[i][1],1));
}
}
for(iter = m.begin();iter != m.end(); iter ++)
answer*=iter->second + 1; // 안입는 경우까지 1더해서 모두를 곱해줌
--answer; //모두 안입은 경우 하나 빼줌
return answer;
}
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스][Lv 1]카카오 인턴 키패드 누르기(2020 카카오 인턴십,pair 쓰기) (0) | 2022.08.15 |
---|---|
[프로그래머스][Lv 2] 주식가격 (0) | 2022.06.10 |
[프로그래머스][Lv 2] 단체사진 찍기 (dfs 길 되돌아가기) (0) | 2022.06.09 |
[프로그래머스][Lv 2] 가장 큰 수 (0) | 2022.06.08 |
[프로그래머스][Lv 2] 네트워크 (BFS) (0) | 2022.06.05 |
Comments