728x90
반응형

프로그래머스 63

프로그래머스, 셔틀버스, 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을 쓰는 것도 핵심이다. 문자열 처리에 정말 도움..

프로그래머스, N으로 표현: C++ [CPP] ★★

처음엔 어려웠다. 왜냐면.. 나는 이전 것의 결과만 생각했다. 즉, [3] 을 구하기 위해서는 [1] 과 [2]의 사칙연산만 하면 되는 줄 알았으나.. 교환법칙이 성립하지 않는 '/' 나눗셈과 '-' 때문에... [2]와 [1]도 계산해야했다. 나는 그것을 몰라서.. 다 틀렸다. https://programmers.co.kr/learn/courses/30/lessons/42895 #맞는 풀이 #include using namespace std; int solution(int N, int number) { int answer = -1; vector vec(10); vec[1].push_back(N); // 문자 한개 쓰인 것 추가. if(number == N) return 1; int seq = 2; wh..

프로그래머스,JadenCase 문자열 만들기: C++ [CPP] ★★

toupper와 tolower를 알고 있다면 쉽게 풀 수 있는 문제였다. 어렵지 않았고 논리적으로만 생각하면 되었다. https://programmers.co.kr/learn/courses/30/lessons/12951 #맞은 풀이 #include using namespace std; string solution(string s) { //check가 true인 상태일 때(공백 다음에 나오는 문자) int i = 0; //true로 시작해야 맨 처음 단어에 대응 가능. bool check = true; while(s[i]){ //공백일 경우 flag하고 넘어감 if(s[i] == ' '){ check = true; i++; continue; }else{ //공백이 아닌 문자를 만났을 경우 //1.첫번째 문..

프로그래머스, 짝지어 제거하기: C++ [CPP] ★★★★

스택을 아는데도 문제를 보면 막상 생각이 안난다. 스택의 문제를 생각해보면 스택은 바로 이전의 것과 비교하는 것이 많이 나온다. 이 문제도 마찬가지였다. https://programmers.co.kr/learn/courses/30/lessons/12973 #맞은 풀이 #include #include #include using namespace std; int solution(string s) { int answer = -1; //문자의 개수가 홀수라면 모두 없앨 수 없음 if(s.size()%2 == 1) return 0; stack stk; for(char x : s){ if(stk.empty()){ stk.push(x); }else{ if(stk.top() == x) stk.pop(); else st..

728x90
반응형