https://programmers.co.kr/learn/courses/30/lessons/17677
#include <string>
#include <map>
using namespace std;
map<string, pair<int, int>> word;
void subS(string str, int turn){
for(int i=0;i<str.size()-1;i++){
if(str[i] >='a' && str[i]<='z' || str[i] >='A' && str[i]<='Z'){
if(str[i+1] >='a' && str[i+1]<='z' || str[i+1] >='A' && str[i+1]<='Z'){}
else continue;
}else continue;
string sub = str.substr(i, 2);
sub[0] = tolower(sub[0]);
sub[1] = tolower(sub[1]);
if(turn == 0){
if(word.insert(make_pair(sub, make_pair(1, 0))).second == false)
word[sub].first++;
}else{
if(word.insert(make_pair(sub, make_pair(0, 1))).second == false)
word[sub].second++;
}
}
}
int solution(string str1, string str2) {
int answer = 0;
subS(str1, 0);
subS(str2, 1);
int uni = 0;
int inter = 0;
map<string, pair<int, int>>::iterator iter = word.begin();
for(;iter!= word.end();iter++){
uni += max(iter->second.first, iter->second.second);
inter += min(iter->second.first, iter->second.second);
}
float jakad = (float)inter / (float)uni;
if(uni == 0)
jakad = 1;
return (int)(jakad*65536);
}
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;
int solution(string str1, string str2) {
vector<int> multiset1 = vector<int>(676, 0);
vector<int> multiset2 = vector<int>(676, 0);
transform(str1.begin(), str1.end(), str1.begin(), ::tolower);
transform(str2.begin(), str2.end(), str2.begin(), ::tolower);
for (int i = 0; i < str1.length() - 1; i++) {
char first = str1[i];
char second = str1[i+1];
if (first >= 97 && first <= 122 && second >= 97 && second <= 122 ) {
multiset1[(first-97)*26 + (second-97)]++;
}
}
for (int i = 0; i < str2.length() - 1; i++) {
char first = str2[i];
char second = str2[i+1];
if (first >= 97 && first <= 122 && second >= 97 && second <= 122 ) {
multiset2[(first-97)*26 + (second-97)]++;
}
}
int numberOfIntersection = 0;
int numberOfUnion = 0;
for (int i = 0; i < 676; i++) {
numberOfUnion += max(multiset1[i], multiset2[i]);
numberOfIntersection += min(multiset1[i], multiset2[i]);
}
if(numberOfUnion == 0)
return 65536;
else
return (int)(((double) numberOfIntersection / (double) numberOfUnion) * (double) 65536);
}