본문 바로가기
Coding Test/Programmers

[Programmers] Lv 2. 할인 행사

by song.ift 2023. 6. 16.

https://school.programmers.co.kr/learn/courses/30/lessons/131127

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

int solution(vector<string> want, vector<int> number, vector<string> discount) {
    int answer = 0;
    
    unordered_map<string, int> m;
    for (int i = 0; i < number.size(); ++i)
        m[want[i]] = number[i];

    unordered_map<string, int> bet;
    for (int i = 0; i < discount.size(); ++i)
    {
        if (i >= 10)
        {
            if (m.find(discount[i - 10]) != m.end())
                --bet[discount[i - 10]];
        }
            
        if (m.find(discount[i]) != m.end())
            ++bet[discount[i]];

        if (bet == m)
            ++answer;
    }

    return answer;
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/blob/4ac025e7b22e02c91bb934f69ec563ada00492d4/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/131127.%E2%80%85%ED%95%A0%EC%9D%B8%E2%80%85%ED%96%89%EC%82%AC/%ED%95%A0%EC%9D%B8%E2%80%85%ED%96%89%EC%82%AC.cpp

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글