전체 글333 [프로그래머스/C언어] 숨어있는 숫자의 덧셈 (1) 문제 문자열 my_string이 매개변수로 주어집니다. my_string안의 모든 자연수들의 합을 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. int solution(const char* my_string) { int answer = 0; for(int i = 0; i < strlen(my_string);i++) { if(isdigit(my_string[i])) answer += (my_string[i] - 48); } return answer; } https://school.programmers.co.kr/learn/courses/30/l.. 2023. 8. 3. [프로그래머스/C언어] 최댓값 만들기 (2) 문제 정수 배열 numbers가 매개변수로 주어집니다. numbers의 원소 중 두 개를 곱해 만들 수 있는 최댓값을 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // numbers_len은 배열 numbers의 길이입니다. int solution(int numbers[], size_t numbers_len) { int answer = 0; int max = numbers[0]*numbers[1]; for(int i = 0; i max) max = numbers[i]*numbers.. 2023. 8. 3. [프로그래머스/C언어] 삼각형의 완성조건 (1) 문제 선분 세 개로 삼각형을 만들기 위해서는 다음과 같은 조건을 만족해야 합니다. 가장 긴 변의 길이는 다른 두 변의 길이의 합보다 작아야 합니다. 삼각형의 세 변의 길이가 담긴 배열 sides이 매개변수로 주어집니다. 세 변으로 삼각형을 만들 수 있다면 1, 만들 수 없다면 2를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // sides_len은 배열 sides의 길이입니다. int solution(int sides[], size_t sides_len) { int answer = 0; int slide; if(sides[0] > sides[1]){ slide = sides[0]; if(sides[2] > slide) slide = si.. 2023. 8. 3. [프로그래머스/C언어] 암호 해독 문제 군 전략가 머쓱이는 전쟁 중 적군이 다음과 같은 암호 체계를 사용한다는 것을 알아냈습니다. 암호화된 문자열 cipher를 주고받습니다. 그 문자열에서 code의 배수 번째 글자만 진짜 암호입니다. 문자열 cipher와 정수 code가 매개변수로 주어질 때 해독된 암호 문자열을 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. char* solution(const char* cipher, int code) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. char* a.. 2023. 8. 3. [프로그래머스/C언어] 인덱스 바꾸기 문제 문자열 my_string과 정수 num1, num2가 매개변수로 주어질 때, my_string에서 인덱스 num1과 인덱스 num2에 해당하는 문자를 바꾼 문자열을 return 하도록 solution 함수를 완성해보세요. 솔루션 #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. char* solution(const char* my_string, int num1, int num2) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. char* answer = (char*)malloc(strlen(my_string)); strcpy(answer, m.. 2023. 8. 3. [프로그래머스/C언어] 가장 큰 수 찾기 문제 정수 배열 array가 매개변수로 주어질 때, 가장 큰 수와 그 수의 인덱스를 담은 배열을 return 하도록 solution 함수를 완성해보세요. 솔루션 #include #include #include // array_len은 배열 array의 길이입니다. int* solution(int array[], size_t array_len) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(1); int max = -1; int max_index = -1; for(int i = 0; i max) { max = array[i]; max_in.. 2023. 8. 3. [프로그래머스/C언어] n의 배수 고르기 문제 정수 n과 정수 배열 numlist가 매개변수로 주어질 때, numlist에서 n의 배수가 아닌 수들을 제거한 배열을 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // numlist_len은 배열 numlist의 길이입니다. int* solution(int n, int numlist[], size_t numlist_len) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(numlist_len*sizeof(int)); int j = 0; for(int i = 0; i < numlist_len; i++) if(numlist[i] .. 2023. 8. 3. [프로그래머스/C언어] 제곱수 판별하기 문제 어떤 자연수를 제곱했을 때 나오는 정수를 제곱수라고 합니다. 정수 n이 매개변수로 주어질 때, n이 제곱수라면 1을 아니라면 2를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include int solution(int n) { int answer = 0; int i; for(i = 2; i 2023. 8. 3. [프로그래머스/C언어] 세균 증식 문제 어떤 세균은 1시간에 두배만큼 증식한다고 합니다. 처음 세균의 마리수 n과 경과한 시간 t가 매개변수로 주어질 때 t시간 후 세균의 수를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include int solution(int n, int t) { int answer = 0; answer = n; for(int i = 0; i < t; i++) answer *= 2; return answer; } https://school.programmers.co.kr/learn/courses/30/lessons/120910 2023. 8. 3. [프로그래머스/C언어] l로 만들기 문제 알파벳 소문자로 이루어진 문자열 myString이 주어집니다. 알파벳 순서에서 "l"보다 앞서는 모든 문자를 "l"로 바꾼 문자열을 return 하는 solution 함수를 완성해 주세요. 솔루션 #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. char* solution(const char* myString) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. char* answer = (char*)malloc(strlen(myString)*sizeof(char)); int i; for(i = 0; i < strlen(myString); i++.. 2023. 8. 3. 이전 1 ··· 20 21 22 23 24 25 26 ··· 34 다음