전체 글333 [프로그래머스/C++] 특별한 이차원 배열 2 문제n × n 크기의 이차원 배열 arr이 매개변수로 주어질 때, arr이 다음을 만족하면 1을 아니라면 0을 return 하는 solution 함수를 작성해 주세요. 0 ≤ i, j 솔루션#include #include using namespace std;int solution(vector> arr) { int answer = 1; for(int i = 0; i https://school.programmers.co.kr/learn/courses/30/lessons/181831 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 21. [프로그래머스/C++] 꼬리 문자열 문제문자열들이 담긴 리스트가 주어졌을 때, 모든 문자열들을 순서대로 합친 문자열을 꼬리 문자열이라고 합니다. 꼬리 문자열을 만들 때 특정 문자열을 포함한 문자열은 제외시키려고 합니다. 예를 들어 문자열 리스트 ["abc", "def", "ghi"]가 있고 문자열 "ef"를 포함한 문자열은 제외하고 꼬리 문자열을 만들면 "abcghi"가 됩니다. 문자열 리스트 str_list와 제외하려는 문자열 ex가 주어질 때, str_list에서 ex를 포함한 문자열을 제외하고 만든 꼬리 문자열을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;string solution(vector str_list, string ex) { stri.. 2025. 2. 21. [프로그래머스/C++] 부분 문자열 문제어떤 문자열 A가 다른 문자열 B안에 속하면 A를 B의 부분 문자열이라고 합니다. 예를 들어 문자열 "abc"는 문자열 "aabcc"의 부분 문자열입니다. 문자열 str1과 str2가 주어질 때, str1이 str2의 부분 문자열이라면 1을 부분 문자열이 아니라면 0을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(string str1, string str2) { int answer = 0; if(str2.find(str1) != -1){ return 1; } else{ return 0; } return answer;} https://sch.. 2025. 2. 20. [프로그래머스/C++] 공백으로 구분하기 1 문제단어가 공백 한 개로 구분되어 있는 문자열 my_string이 매개변수로 주어질 때, my_string에 나온 단어를 앞에서부터 순서대로 담은 문자열 배열을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;vector solution(string my_string) { vector answer; string tmp = ""; for(int i = 0 ; i https://school.programmers.co.kr/learn/courses/30/lessons/181869 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programm.. 2025. 2. 20. [프로그래머스/C++] 배열의 원소 삭제하기 문제정수 배열 arr과 delete_list가 있습니다. arr의 원소 중 delete_list의 원소를 모두 삭제하고 남은 원소들은 기존의 arr에 있던 순서를 유지한 배열을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include #include using namespace std;vector solution(vector arr, vector delete_list) { vector answer; for(auto n:delete_list){ arr.erase(remove(arr.begin(), arr.end(),n),arr.end()); } return arr;} https://school.programmers.co.kr/learn.. 2025. 2. 20. [프로그래머스/C++] 덧셈식 출력하기 문제두 정수 a, b가 주어질 때 다음과 같은 형태의 계산식을 출력하는 코드를 작성해 보세요. a + b = c 솔루션#include using namespace std;int main(void) { int a; int b; cin >> a >> b; cout https://school.programmers.co.kr/learn/courses/30/lessons/181947 2025. 2. 20. [프로그래머스/C++] 9로 나눈 나머지 문제음이 아닌 정수를 9로 나눈 나머지는 그 정수의 각 자리 숫자의 합을 9로 나눈 나머지와 같은 것이 알려져 있습니다. 이 사실을 이용하여 음이 아닌 정수가 문자열 number로 주어질 때, 이 정수를 9로 나눈 나머지를 return 하는 solution 함수를 작성해주세요. 솔루션#include #include using namespace std;int solution(string number) { int answer = 0; for(auto c:number){ answer += c - '0'; } return answer%9;} https://school.programmers.co.kr/learn/courses/30/lessons/181914 프로그래머스SW개발자를.. 2025. 2. 20. [프로그래머스/C++] 조건에 맞게 수열 변환하기 3 문제정수 배열 arr와 자연수 k가 주어집니다. 만약 k가 홀수라면 arr의 모든 원소에 k를 곱하고, k가 짝수라면 arr의 모든 원소에 k를 더합니다. 이러한 변환을 마친 후의 arr를 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(vector arr, int k) { vector answer; if(k%2!=0){ for(auto n:arr){ answer.push_back(n*k); } } else{ for(auto n:arr){ answer.push_back(n+k); } .. 2025. 2. 20. [프로그래머스/C++] 주사위 게임 1 문제1부터 6까지 숫자가 적힌 주사위가 두 개 있습니다. 두 주사위를 굴렸을 때 나온 숫자를 각각 a, b라고 했을 때 얻는 점수는 다음과 같습니다. a와 b가 모두 홀수라면 a2 + b2 점을 얻습니다. a와 b 중 하나만 홀수라면 2 × (a + b) 점을 얻습니다. a와 b 모두 홀수가 아니라면 |a - b| 점을 얻습니다. 두 정수 a와 b가 매개변수로 주어질 때, 얻는 점수를 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;int solution(int a, int b) { int answer = 0; if(a%2!=0 && b%2!=0){ return a*a+b*b; } els.. 2025. 2. 20. [프로그래머스/C++] 주사위의 개수 문제머쓱이는 직육면체 모양의 상자를 하나 가지고 있는데 이 상자에 정육면체 모양의 주사위를 최대한 많이 채우고 싶습니다. 상자의 가로, 세로, 높이가 저장되어있는 배열 box와 주사위 모서리의 길이 정수 n이 매개변수로 주어졌을 때, 상자에 들어갈 수 있는 주사위의 최대 개수를 return 하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(vector box, int n) { return (box[0]/n)*(box[1]/n)*(box[2]/n);} https://school.programmers.co.kr/learn/courses/30/lessons/120845 프로그래머스SW개발자를 위한 평가, 교육, 채.. 2025. 2. 20. 이전 1 2 3 4 5 6 7 8 ··· 34 다음