본문 바로가기

전체 글333

[프로그래머스/C++] 배열 뒤집기 문제정수가 들어 있는 배열 num_list가 매개변수로 주어집니다. num_list의 원소의 순서를 거꾸로 뒤집은 배열을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include #include using namespace std;vector solution(vector num_list) { vector answer; reverse(num_list.begin(), num_list.end()); return num_list;} https://school.programmers.co.kr/learn/courses/30/lessons/120821 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스.. 2025. 2. 11.
[프로그래머스/C++] 제곱수 판별하기 문제어떤 자연수를 제곱했을 때 나오는 정수를 제곱수라고 합니다. 정수 n이 매개변수로 주어질 때, n이 제곱수라면 1을 아니라면 2를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include #include using namespace std;int solution(int n) { if(sqrt(n) == int(sqrt(n))){ return 1; } else{ return 2; }} 메모곱셈으로 풀면 오버플로우가 발생한다. https://school.programmers.co.kr/learn/courses/30/lessons/120909 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제.. 2025. 2. 11.
[프로그래머스/C++] 문자열안에 문자열 문제문자열 str1, str2가 매개변수로 주어집니다. str1 안에 str2가 있다면 1을 없다면 2를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(string str1, string str2) { int isfind = str1.find(str2); if(isfind == -1){ return 2; } else{ return 1; }} 메모find함수#include find(value) https://school.programmers.co.kr/learn/courses/30/lessons/120908 프로그래머스SW개발자를 위한 평가, 교육, .. 2025. 2. 11.
[프로그래머스/C++] 배열 원소의 길이 문제문자열 배열 strlist가 매개변수로 주어집니다. strlist 각 원소의 길이를 담은 배열을 return하도록 solution 함수를 완성해주세요.솔루션#include #include using namespace std;vector solution(vector strlist) { vector answer; for(int i = 0; i  메모push_back함수 : 벡터에 추가 https://school.programmers.co.kr/learn/courses/30/lessons/120854 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 11.
[프로그래머스/C++] 피자 나눠 먹기 (3) 문제머쓱이네 피자가게는 피자를 두 조각에서 열 조각까지 원하는 조각 수로 잘라줍니다. 피자 조각 수 slice와 피자를 먹는 사람의 수 n이 매개변수로 주어질 때, n명의 사람이 최소 한 조각 이상 피자를 먹으려면 최소 몇 판의 피자를 시켜야 하는지를 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include using namespace std;int solution(int slice, int n) { int answer = 0; answer = n / slice; if(n > slice*answer){ answer += 1; } return answer;} https://school.programmers.co.kr/learn/c.. 2025. 2. 11.
[프로그래머스/C++] 짝수의 합 문제정수 n이 주어질 때, n이하의 짝수를 모두 더한 값을 return 하도록 solution 함수를 작성해주세요. 솔루션#include #include using namespace std;int solution(int n) { int answer = 0; for(int i = 2; i  https://school.programmers.co.kr/learn/courses/30/lessons/120831 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 11.
[프로그래머스/C++] 양꼬치 문제머쓱이네 양꼬치 가게는 10인분을 먹으면 음료수 하나를 서비스로 줍니다. 양꼬치는 1인분에 12,000원, 음료수는 2,000원입니다. 정수 n과 k가 매개변수로 주어졌을 때, 양꼬치 n인분과 음료수 k개를 먹었다면 총얼마를 지불해야 하는지 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include using namespace std;int solution(int n, int k) { int answer = 0; answer += n * 12000; answer += (k-n/10) * 2000; return answer;} https://school.programmers.co.kr/learn/courses/30/lessons/120830 프로.. 2025. 2. 11.
[프로그래머스/C++] 각도기 문제각에서 0도 초과 90도 미만은 예각, 90도는 직각, 90도 초과 180도 미만은 둔각 180도는 평각으로 분류합니다. 각 angle이 매개변수로 주어질 때 예각일 때 1, 직각일 때 2, 둔각일 때 3, 평각일 때 4를 return하도록 solution 함수를 완성해주세요. -예각 : 0 -직각 : angle = 90 -둔각 : 90 -평각 : angle = 180 솔루션#include #include using namespace std;int solution(int angle) { int answer = 0; if (angle  메모for, elseif 2025. 2. 11.
[프로그래머스/C++] 배열의 평균값 문제정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소의 평균값을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include #include using namespace std;double solution(vector numbers) { double answer = 0; double sum = accumulate(numbers.begin(), numbers.end(), 0); return sum / numbers.size();} https://school.programmers.co.kr/learn/courses/30/lessons/120817 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발.. 2025. 2. 11.
[프로그래머스/C++] 나이 출력 문제머쓱이는 선생님이 몇 년도에 태어났는지 궁금해졌습니다. 2022년 기준 선생님의 나이 age가 주어질 때, 선생님의 출생 연도를 return 하는 solution 함수를 완성해주세요 솔루션#include #include using namespace std;int solution(int age) { return 2022 - age + 1;} https://school.programmers.co.kr/learn/courses/30/lessons/120820 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 10.