Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 다익스트라
- vector
- MySQL
- unordered_map
- 문자열
- 코테
- dfs
- Dijkstra
- 코테준비
- 알고리즘
- DP
- 동적계획법
- 다이나믹프로그래밍
- 코딩테스트연습
- 우선순위큐
- String
- sql고득점kit
- 시스템콜
- 스택
- 플로이드와샬
- 정렬
- MAP
- 백준
- 리시프
- substr
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 최대공약수
- 프로그래머스
- C++
- set
Archives
- Today
- Total
YeJin's Footsteps
문자열 압축 본문
문제 링크
https://programmers.co.kr/learn/courses/30/lessons/60057
코딩테스트 연습 - 문자열 압축
데이터 처리 전문가가 되고 싶은 "어피치"는 문자열을 압축하는 방법에 대해 공부를 하고 있습니다. 최근에 대량의 데이터 처리를 위한 간단한 비손실 압축 방법에 대해 공부를 하고 있는데, 문
programmers.co.kr
문제 풀이 코드
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int solution(string s) {
int len=s.size();
int answer = len;
for(int i=1; i<=len/2; i++){
string ansS="";
string subS=s.substr(0,i);
int cnt=1;
for(int j=i; j<=len; j+=i){
if(subS==s.substr(j,i)) cnt++;
else{
if(cnt==1) ansS+=subS;
else ansS+=(to_string(cnt)+subS);
subS=s.substr(j,i);
cnt=1;
}
}
if((len%i)!=0) ansS+=s.substr((len/i)*i);
if(answer>ansS.size()) answer=ansS.size();
}
return answer;
}
문자열 문제.. 나에겐 너무 어려운 문제...
2단계지만 반복문 도는 것과 모든 조건들이 생각하기 어려웠다.
뚝딱뚝딱 못푸는 내가 답답하다.

'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글
2407번: 조합 (0) | 2021.08.06 |
---|---|
2 x n 타일링 (0) | 2021.07.31 |
로또의 최고 순위와 최저 순위 (0) | 2021.07.30 |
9370번: 미확인 도착지 (0) | 2021.07.21 |
1238번: 파티 (0) | 2021.07.20 |
Comments