본문 바로가기

전체 글333

[프로그래머스/C++] 더 크게 합치기 문제연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다. 12 ⊕ 3 = 123 3 ⊕ 12 = 312 양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요. 단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다. 솔루션#include #include using namespace std;int solution(int a, int b) { if(stoi(to_string(a)+to_string(b)) > stoi(to_string(b)+to_string(a))){ return stoi(to_string(a)+to_string(b)); } .. 2025. 2. 21.
[프로그래머스/C++] 이어 붙인 수 문제정수가 담긴 리스트 num_list가 주어집니다. num_list의 홀수만 순서대로 이어 붙인 수와 짝수만 순서대로 이어 붙인 수의 합을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(vector num_list) { string even = ""; string odd = ""; for(auto n:num_list){ if(n%2==0){ even+=to_string(n); } else{ odd+=to_string(n); } } return stoi(even)+stoi(odd);} .. 2025. 2. 21.
[프로그래머스/C++] 두 수의 연산값 비교하기 문제연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다. 12 ⊕ 3 = 123 3 ⊕ 12 = 312 양의 정수 a와 b가 주어졌을 때, a ⊕ b와 2 * a * b 중 더 큰 값을 return하는 solution 함수를 완성해 주세요. 단, a ⊕ b와 2 * a * b가 같으면 a ⊕ b를 return 합니다. 솔루션#include #include using namespace std;int solution(int a, int b) { if(stoi(to_string(a)+to_string(b)) > 2*a*b){ return stoi(to_string(a)+to_string(b)); } else{ retur.. 2025. 2. 21.
[프로그래머스/C++] 뒤에서 5등 위로 문제정수로 이루어진 리스트 num_list가 주어집니다. num_list에서 가장 작은 5개의 수를 제외한 수들을 오름차순으로 담은 리스트를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include #include using namespace std;vector solution(vector num_list) { vector answer; sort(num_list.begin(), num_list.end()); for(int i = 5; i  https://school.programmers.co.kr/learn/courses/30/lessons/181852 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장.. 2025. 2. 21.
[프로그래머스/C++] 문자열 정렬하기 (2) 문제영어 대소문자로 이루어진 문자열 my_string이 매개변수로 주어질 때, my_string을 모두 소문자로 바꾸고 알파벳 순서대로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include #include using namespace std;string solution(string my_string) { string answer = ""; for(auto c:my_string){ answer += tolower(c); } sort(answer.begin(), answer.end()); return answer;} https://school.programmers.co.kr/learn/courses/30/less.. 2025. 2. 21.
[프로그래머스/C++] 주사위 게임 2 문제1부터 6까지 숫자가 적힌 주사위가 세 개 있습니다. 세 주사위를 굴렸을 때 나온 숫자를 각각 a, b, c라고 했을 때 얻는 점수는 다음과 같습니다. 세 숫자가 모두 다르다면 a + b + c 점을 얻습니다. 세 숫자 중 어느 두 숫자는 같고 나머지 다른 숫자는 다르다면 (a + b + c) × (a2 + b2 + c2 )점을 얻습니다. 세 숫자가 모두 같다면 (a + b + c) × (a2 + b2 + c2 ) × (a3 + b3 + c3 )점을 얻습니다. 세 정수 a, b, c가 매개변수로 주어질 때, 얻는 점수를 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include #include using namespace std;int solution(int a, .. 2025. 2. 21.
[프로그래머스/C++] x 사이의 개수 문제문자열 myString이 주어집니다. myString을 문자 "x"를 기준으로 나눴을 때 나눠진 문자열 각각의 길이를 순서대로 저장한 배열을 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(string myString) { vector answer; int cnt = 0; for(auto c:myString){ if(c == 'x'){ answer.push_back(cnt); cnt = 0; } else{ cnt++; } } answer.push_back(c.. 2025. 2. 21.
[프로그래머스/C++] 정수 찾기 문제정수 리스트 num_list와 찾으려는 정수 n이 주어질 때, num_list안에 n이 있으면 1을 없으면 0을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include #include using namespace std;int solution(vector num_list, int n) { if(find(num_list.begin(), num_list.end(), n)==num_list.end()){ return 0; } else{ return 1; }} https://school.programmers.co.kr/learn/courses/30/lessons/181840 프로그래머스SW개발자를 위한 평가, 교육, 채용까지.. 2025. 2. 21.
[프로그래머스/C++] 부분 문자열인지 확인하기 문제부분 문자열이란 문자열에서 연속된 일부분에 해당하는 문자열을 의미합니다. 예를 들어, 문자열 "ana", "ban", "anana", "banana", "n"는 모두 문자열 "banana"의 부분 문자열이지만, "aaa", "bnana", "wxyz"는 모두 "banana"의 부분 문자열이 아닙니다. 문자열 my_string과 target이 매개변수로 주어질 때, target이 문자열 my_string의 부분 문자열이라면 1을, 아니라면 0을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;int solution(string my_string, string target) { if(my_string.find(targ.. 2025. 2. 21.
[프로그래머스/C++] 0 떼기 문제정수로 이루어진 문자열 n_str이 주어질 때, n_str의 가장 왼쪽에 처음으로 등장하는 0들을 뗀 문자열을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;string solution(string n_str) { int i; for(i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181847 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 21.