#include <algorithm>
#include <string>
#include <map>
#include <iostream>
using namespace std;
int solution(string str1, string str2) {
int answer = 0;
int sum=0,cnt=0;
map<string,int>A,B,m;
for(int i=0; i<str1.length(); i++){ //๋๋ฌธ์->์๋ฌธ์ ๋ณ๊ฒฝ
str1[i]=tolower(str1[i]);
}
for(int i=0; i<str2.length(); i++){ //๋๋ฌธ์->์๋ฌธ์ ๋ณ๊ฒฝ
str2[i]=tolower(str2[i]);
}
for(int i=0; i<str1.length()-1; i++){
if(str1[i]>='a'&&str1[i]<='z'&&str1[i+1]>='a'&&str1[i+1]<='z'){ //์ซ์์ผ๋
string temp=str1.substr(i,2);
A[temp]++;
m[temp]++;
}
}
for(int i=0; i<str2.length()-1; i++){
if(str2[i]>='a'&&str2[i]<='z'&&str2[i+1]>='a'&&str2[i+1]<='z'){ //์ซ์์ผ๋
string temp=str2.substr(i,2);
B[temp]++;
m[temp]++;
}
}
for(auto it=m.begin(); it!=m.end(); it++){
cnt+=min(A[it->first],B[it->first]);
sum+=max(A[it->first],B[it->first]);
}
if(sum==0&&cnt==0) sum=1,cnt=1;
answer=(double)cnt/(double)sum*65536;
return answer;
}
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ ( Level 2, 2021 ์นด์นด์ค ์ธํด์ญ) (0) | 2021.10.19 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๊ฐ์ ์ซ์๋ ์ซ์ด (Level 1) (0) | 2021.10.19 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๊ฐ์ฅ ํฐ ์ (Level 2) (0) | 2021.10.19 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - N๊ฐ์ ์ต์๊ณต๋ฐฐ์ ( Level 2 ) (0) | 2021.10.19 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - K๋ฒ์งธ ์ ( Level 1) (0) | 2021.10.19 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - JadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐ ( Level 2 ) (0) | 2021.10.19 |
๋๊ธ