https://school.programmers.co.kr/learn/courses/30/lessons/17677
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
using namespace std;
void setMap(unordered_map<string, int> &map, string str, unordered_set<string> &set)
{
for (int i = 0; i < str.size() - 1; i++)
{
string s = str.substr(i, 2);
if (!islower(s[0]) || !islower(s[1]))
continue ;
set.insert(s);
map[s] += 1;
}
}
int solution(string str1, string str2) {
int cnt_inter = 0, cnt_combin = 0;
for (int i = 0; i < str1.size(); i++) // 다 소문자로 바꿔줌
str1[i] = tolower(str1[i]);
for (int i = 0; i < str2.size(); i++)
str2[i] = tolower(str2[i]);
unordered_map<string, int> map1, map2;
unordered_set<string> set;
setMap(map1, str1, set);
setMap(map2, str2, set);
for (auto s : set)
{
cnt_combin += max(map1[s], map2[s]);
cnt_inter += min(map1[s], map2[s]);
}
if (set.size() == 0) // 집합 A와 집합 B가 모두 공집합일 경우에는 나눗셈이 정의되지 않으니 따로 J(A, B) = 1
return (65536);
return 65536 * cnt_inter / cnt_combin;
}
하아 조건 잘못 보고 테케 한참 들여다봤다. french 면 fr en ch 가 아니라 fr re en nc ch 다. 문제를 잘 읽자 좀
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 네트워크 c++ (2) | 2023.07.03 |
---|---|
프로그래머스 타겟넘버 c++ (2) | 2023.07.02 |
프로그래머스 정수 삼각형 c++ (2) | 2023.06.28 |
프로그래머스 할인 행사 c++ (4) | 2023.06.24 |
프로그래머스 튜플 c++ (2) | 2023.06.22 |