728x90
반응형
문제
분석
압축한다.. 딱히 분석할게 없었다.
구현
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(string s){
int answer = 0;
int findCount = 0;
int index = 0;
int minCount = 987654321;
string findString="";
string compressString = "";
for(int i =1; i <= s.size(); i++)
{
findCount = i;
findString = s.substr(0,findCount);
int matchCount = 0;
for(int j = 0; j< s.size(); j+=findCount){
string tmpString = s.substr(j,findCount);
if( findString == tmpString ){
matchCount++;
} else {
if( matchCount>1){
compressString += to_string(matchCount)+findString;
} else {
compressString += findString;
}
findString = tmpString;
j-=findCount;
matchCount = 0;
}
}
if( matchCount>1){
compressString += to_string(matchCount)+findString;
} else{
compressString+=findString;
}
if( compressString.size() < minCount ){
minCount = compressString.size();
}
compressString="";
}
answer = minCount;
return answer;
}
문제링크: https://programmers.co.kr/learn/courses/30/lessons/60057
코딩테스트 연습 - 문자열 압축
데이터 처리 전문가가 되고 싶은 "어피치"는 문자열을 압축하는 방법에 대해 공부를 하고 있습니다. 최근에 대량의 데이터 처리를 위한 간단한 비손실 압축 방법에 대해 공부를 하고 있는데, 문
programmers.co.kr
728x90
반응형
'Algorithm > 프로그래머스 알고리즘' 카테고리의 다른 글
[프로그래머스] 방문 길이 (0) | 2021.05.15 |
---|---|
[프로그래머스] 다트게임 (0) | 2021.05.15 |
[프로그래머스] 올바른 괄호 (0) | 2021.05.15 |
[프로그래머스] 삼각 달팽이 (0) | 2021.05.15 |
[프로그래머스] 기능개발 (0) | 2021.04.06 |
댓글