안녕하십니까. Eun🦆입니다.
풀이법 입니다.
#include <string>
#include <iostream>
#include <cstring>
using namespace std;
int solution(string str1, string str2) {
int answer = 0;
int len_str1 = 0;
int len_str2 = 0;
int arr1_cnt = 0;
int arr2_cnt = 0;
string ARR1[1000];
string ARR2[1000];
//printf("'A'=%d,'a'=%d\n",'A','a');
for(int i=0;i<str1.length()-1;i++)
{
if((('a' <= str1[i] & str1[i] <= 'z') || ('A' <= str1[i] & str1[i] <= 'Z')) &
(('a' <= str1[i+1] & str1[i+1] <= 'z') || ('A' <= str1[i+1] & str1[i+1] <= 'Z')))
{
len_str1++;
if(('A' <= str1[i] & str1[i] <= 'Z'))
str1[i] += 32;
if(('A' <= str1[i+1] & str1[i+1] <= 'Z'))
str1[i+1] += 32;
//printf("str1[%d]=%c,str1[%d]=%c\n",i,str1[i],i+1,str1[i+1]);
ARR1[arr1_cnt] += str1[i]; // 문자열 합치기!
ARR1[arr1_cnt++] += str1[i+1];
}
}
for(int i=0;i<str2.length();i++)
{
if((('a' <= str2[i] & str2[i] <= 'z') || ('A' <= str2[i] & str2[i] <= 'Z')) &
(('a' <= str2[i+1] & str2[i+1] <= 'z') || ('A' <= str2[i+1] & str2[i+1] <= 'Z')))
{
len_str2++;
if(('A' <= str2[i] & str2[i] <= 'Z'))
str2[i] += 32;
if(('A' <= str2[i+1] & str2[i+1] <= 'Z'))
str2[i+1] += 32;
//printf("str2[%d]=%c,str2[%d]=%c\n",i,str2[i],i+1,str2[i+1]);
ARR2[arr2_cnt] += str2[i];
ARR2[arr2_cnt++] += str2[i+1];
}
}
//printf("len_str1=%d,len_str2=%d\n",len_str1,len_str2);
int same = 0;
int dif = 0;
for(int i=0;i<arr1_cnt;i++)
{
for(int j=0;j<arr2_cnt;j++)
{
if(ARR1[i]==ARR2[j])
{
same++;
//printf("same! ARR1[%d]=%c%c, ARR2[%d]=%c%c\n",i,str1[i],str1[i+1],j,str2[j],str2[j+1]);
ARR1[i] = '<';
ARR2[j] = '>';
}
else
dif++;
}
}
//printf("same=%d,dif=%d\n",same,dif);
if(same==len_str1 & same==len_str2)
answer = 65536;
else
answer = 65536*same/(len_str1+len_str2-same);
return answer;
}
'개발 > Coding Test' 카테고리의 다른 글
[프로그래머스 C++ Lv2] 압축 (0) | 2022.06.07 |
---|---|
[프로그래머스 C++ Lv2] 프렌즈4블록 (0) | 2022.06.07 |
[프로그래머스 C++ Lv2] 예상 대진표 (0) | 2022.06.07 |
[프로그래머스 C++ Lv2] 영어 끝말잇기 (0) | 2022.06.07 |
[프로그래머스 C++ Lv2] 점프와 순간 이동 (0) | 2022.06.06 |
댓글