728x90
반응형
목차
https://www.acmicpc.net/problem/9375
문제
문제 구현 방향
문자열을 종류만 빼서 map에 string int pair로 넣은 뒤 수학적 계산을 해주면 되는 문제이다.
주의할 점
//넣어주면 틀리게 된다
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
참고
https://be-senior-developer.tistory.com/52
코드 구현
#include <iostream>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;
map<string, int> m;
vector<int> v;
void split(string str, string delimeter) { //문자열을 잘라주는 함수
long long int pos;
string token="";
while ((pos = str.find(delimeter)) != string::npos) {
token = str.substr(0, pos);
str.erase(0, pos + delimeter.length());
}
if (m[str]) {
m[str]++;
}
else {
m[str] = 1;
}
}
int main() {
int T, n, sum=1;
string str;
cin >> T;
if (T == 0) { //테스트케이스가 0일 경우는 0 출력 후 종료
cout << 0;
return 0 ;
}
for (int i = 0; i < T; i++) {
cin >> n;
getchar();
sum = 1; //초기화 필수
m.clear();
for (int j = 0; j < n; j++) {
getline(cin, str);
split(str, " ");
}
for (auto k = m.begin(); k != m.end(); k++) {
sum *= (k->second + 1); //안입었을 경우를 생각해 +1해서 곱해준다
}
cout << sum - 1<<"\n"; // 모두 다 안입었을 경우를 빼준다.
}
}
반응형
'백준 문제풀이' 카테고리의 다른 글
[백준][완전 탐색] 15686 치킨 배달 c++구현 (3) | 2024.05.09 |
---|---|
[백준][문자열] 2870 수학숙제 c++구현 (0) | 2024.05.07 |
[백준][문자열] 1213 팰린드롬 만들기 c++ 구현 (0) | 2024.05.04 |
[백준][dfs] 1068 트리 c++ 구현 (0) | 2024.05.04 |
[백준][bfs] 14502 연구소 c++ 구현 (0) | 2024.05.01 |