1. 경우의 수를 구하는 방법은 모든 의상분류의 의상 수 +1한 값을 곱한 값에 1(알몸 상태)을 뺀값이다.

2. map을 사용하여 item_category의 중복 없이 입력받는다.

3. map["item_category"]++;  와 같이 입력받을 경우 해당 의상분류마다 카운팅이 가능하다.

 

케이스별 답을 출력할때 \n을 해주지 않으면 틀렸습니다가 나온다.

 

#include <iostream>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;

    while(t--){
        map<string, int> m;
        int n;
        int result = 1;

        cin >> n;
        for (int i = 0; i < n; i++){
            string a, b;
            cin >> a >> b;
            m[b]++;
        }

        for (auto i : m){
            result *= (i.second + 1);
        }

        cout << result - 1 << "\n";
    }
}

 

js쓰다가 c++로 넘어오니 ""와 ''의 차이 때문에 컴파일 에러가 많이 났다.

 

'Algorithm' 카테고리의 다른 글

[백준] 11403번 경로 찾기 c++  (0) 2022.12.25
[백준] 14500 테트로미노 c++  (0) 2022.12.24
[백준] 5525번 IOIOI c++  (0) 2022.12.10
[백준] 5430번 AC c++  (0) 2022.12.10
[백준] 10026번 적록색양 c++  (0) 2022.11.30

+ Recent posts