백준 알고리즘(C++)
백준 9375번 패션왕 신해빈(C++)
coding232624
2024. 2. 13. 00:05
문제
https://www.acmicpc.net/problem/9375
9375번: 패션왕 신해빈
첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.
www.acmicpc.net
해설
map<string,int> mp;활용하기
C++에서는 mp[type]++;값 없을 경우 새로운 값생성 후 ++
코드
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
|
#include<bits/stdc++.h>
using namespace std;
int n , m;
string name,type;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> n ;
for (int i=0;i<n;i++){
map<string,int> mp;
long long ret = 1;
cin >> m;
for (int j=0;j<m;j++){
cin >> name >> type;
mp[type]++;
}
for(auto count:mp){
ret *= ((long long)count.second+1);
}
ret --;
cout << ret << "\n";
}
return 0;
}
|
cs |