728x90
반응형

문제풀이(Problem Solving) 323

백준, BOJ, 5582번, 공통 부분 문자열 C++ [CPP] ★★★

이 문제는 알고리즘을 알 경우 쉽게 풀 수 있다. 쉽게 생각하기는 어려운데 알고 있다면 바로 풀 수 있다. https://www.acmicpc.net/problem/5582 5582번: 공통 부분 문자열 두 문자열이 주어졌을 때, 두 문자열에 모두 포함된 가장 긴 공통 부분 문자열을 찾는 프로그램을 작성하시오. 어떤 문자열 s의 부분 문자열 t란, s에 t가 연속으로 나타나는 것을 말한다. 예를 들 www.acmicpc.net #맞은 풀이 #include using namespace std; //LCS[i][j] => s1의 i번째 문자열과 s2의 j번째 문자열까지의 최장 공통 문자열수 int LCS[4001][4001]; int main(){ string s1,s2; cin >> s1 >> s2; in..

프로그래머스, 셔틀버스, C++ [CPP] ★★★★

어려우면서도 쉬운 문제다. 다시 말하자면 생각은 쉬운데 구현이 어렵다. https://school.programmers.co.kr/learn/courses/30/lessons/17678 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #맞은 풀이 #include #include #include #include #include #include using namespace std; string func(int x){ if(x>= 10){ return to_string(x); }else{ return "0" + to_string(x); } } string sol..

프로그래머스, 방금그곡, C++ [CPP] ★★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/17683 문자열 처리를 위한 문제다. C++로는 어렵지만 stringstream으로 헤쳐나가보자 중요하다. c++의 문자열 처리는 stringstream에게 맡기라고 그리고 #도 한글자로 쳐야하는 처리를 해주는게 까다롭다. #맞는 풀이 #include #include #include #include #include using namespace std; struct mus{ int playtime; int idx; string title; }; bool comp(mus a, mus b){ if(a.playtime == b.playtime){ return a.idx < b.idx; } return a.p..

프로그래머스, 파일명 정렬, C++ [CPP] ★★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/17686# 어렵지 않다. 다만 까다로울 수 있다. 특히 number랑 head를 분리할 때 신경써주어야 한다. #맞은 풀이 #include #include #include #include using namespace std; struct File{ string head = ""; string number = ""; string totalName = ""; int idx = -1; }; bool cmp (const File &a, const File &b){ string head1 =""; string head2 =""; int number1 = -1; int number2 = -1; for(char ..

프로그래머스, 프렌즈4블록, C++ [CPP] ★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/17679 이건 그냥 구현문제다. 블럭 게임은 그냥 말한대로 구현만 하면된다. 하지만 어떤 순서로 해야할지 내가 정해야 하는 그런 문제다. 어렵다. 생각하기는 어렵지만 생각만 하면 구현할 수 있다,. #맞은 풀이 #include #include #include #include using namespace std; int solution(int m, int n, vector board) { int answer = 0; //m = 행, row //n = 열, col auto temp = board; vector queue(n); //n개의 열을 큐로 만듦 //board에서 4개쌍을 찾아야함 while(1)..

프로그래머스, 압축, C++ [CPP] ★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/17684 문자열 가지고 노는 문제다. substr을 유용하게 쓸 수 있는 문제다. 그냥 따라서 구현하면 된다. #맞은 풀이 #include #include #include using namespace std; map alpha; vector solution(string msg) { vector answer; int idx = 27; alpha["A"]=1; alpha["B"]=2; alpha["C"]=3; alpha["D"]=4; alpha["E"]=5; alpha["F"]=6; alpha["G"]=7; alpha["H"]=8; alpha["I"]=9; alpha["J"]=10; alpha["K"]=..

프로그래머스, 후보키, C++ [CPP] ★★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/42890 나는.. 어려웠다. 그래서 다른 사람풀이를 보고 이해했다. 비트마스크를 써서 비교를 하는 것도 처음엔 생각하지 못했고 유일성이나 최소성에 관한 구현도 조금 힘들었다. 그래도 주석을 달면서 비트마스킹에 대한 감을 잡았다. #맞은 풀이 #include #include #include #include #include #include using namespace std; // 최소성 확인 bool possi(vector vec,int now){ //지금까지 유일성이 확인된 vec 컨테이너의 원소들에 대해서 //now가 최소성을 가지는지 확인 for(int i = 0; i < vec.size(); i..

프로그래머스, 오픈채팅방, C++ [CPP] ★★★★

https://school.programmers.co.kr/learn/courses/30/lessons/42888 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 아주 좋은 문제라고 볼 수 있다. 문자열 처리를 함과 동시에 구현 문제이다. 감이 오면 쉽지만.. 어떻게 할지 모른다면 못푼다..ㅠ 내 생각의 흐름을 보여주자면 결국 uid에 해당하는 마지막 변경 닉네임만이 중요하다. 문제의 출력도 실시간이 아닌 마지막, 모두 다 처리했을 때를 물어본다. 이것이 핵심이라고 할 수 있다. 그리고 stringstream을 쓰는 것도 핵심이다. 문자열 처리에 정말 도움..

728x90
반응형