[프로그래머스] 롤케이크 자르기
#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
int solution(vector<int> topping) {
map<int, int> cake1;
map<int, int> cake2;
int N = topping.size();
for(int i = 0; i< N; ++i){
if(cake2.find(topping[i]) == cake2.end()){
cake2[topping[i]] = 1;
}
else{
cake2[topping[i]] = cake2[topping[i]] + 1;
}
}
int answer = 0;
for(int i = 0; i<N-1; ++i){
cake2[topping[i]] = cake2[topping[i]] - 1;
if(cake2[topping[i]] == 0){
auto it = cake2.find(topping[i]);
cake2.erase(it);
}
if(cake1.find(topping[i])==cake1.end()){
cake1[topping[i]] = 1;
}
else cake1[topping[i]] = cake1[topping[i]] + 1;
if(cake1.size() == cake2.size()) answer++;
}
return answer;
}