전체 글333 [프로그래머스/C언어] 대문로 바꾸기 문제 알파벳으로 이루어진 문자열 myString이 주어집니다. 모든 알파벳을 대문자로 변환하여 return 하는 solution 함수를 완성해 주세요. 솔루션 #include #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. char* solution(const char* myString) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. char* answer = (char*)malloc(100000); for(int i = 0; i < strlen(myString); i++) answer[i] = toupper(myString[i]); retur.. 2023. 8. 1. [프로그래머스/C언어] 원하는 문자열 찾기 문제 알파벳으로 이루어진 문자열 myString과 pat이 주어집니다. myString의 연속된 부분 문자열 중 pat이 존재하면 1을 그렇지 않으면 0을 return 하는 solution 함수를 완성해 주세요. 단, 알파벳 대문자와 소문자는 구분하지 않습니다. 솔루션 #include #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. int solution(const char* myString, const char* pat) { int answer = 0; int j = 0; for(int i = 0; i < strlen(myString); i++) { if(tolower(myString[i]) == tol.. 2023. 8. 1. [프로그래머스/C언어] 길이에 따른 연산 문제 정수가 담긴 리스트 num_list가 주어질 때, 리스트의 길이가 11 이상이면 리스트에 있는 모든 원소의 합을 10 이하이면 모든 원소의 곱을 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // num_list_len은 배열 num_list의 길이입니다. int solution(int num_list[], size_t num_list_len) { int answer = 0; if(num_list_len >= 11) for(int i = 0; i < num_list_len; i++) answer += num_list[i]; else{ answer = 1; for(int j = 0; j < num_list_len; j++) answer .. 2023. 8. 1. [프로그래머스/C언어] 조건에 맞게 수열 변환하기 1 문제 정수 배열 arr가 주어집니다. arr의 각 원소에 대해 값이 50보다 크거나 같은 짝수라면 2로 나누고, 50보다 작은 홀수라면 2를 곱합니다. 그 결과인 정수 배열을 return 하는 solution 함수를 완성해 주세요. 솔루션 #include #include #include // arr_len은 배열 arr의 길이입니다. int* solution(int arr[], size_t arr_len) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(arr_len*sizeof(int)); for(int i = 0; i 50 || arr[i] .. 2023. 8. 1. [프로그래머스/C언어] n보다 커질 때까지 더하기 문제 정수 배열 numbers와 정수 n이 매개변수로 주어집니다. numbers의 원소를 앞에서부터 하나씩 더하다가 그 합이 n보다 커지는 순간 이때까지 더했던 원소들의 합을 return 하는 solution 함수를 작성해 주세요. 솔루션 #include #include #include // numbers_len은 배열 numbers의 길이입니다. int solution(int numbers[], size_t numbers_len, int n) { int answer = 0; for(int i = 0; i n) break; } return answer; } https://school.programmers.c.. 2023. 8. 1. [프로그래머스/C언어] 홀수 vs 짝수 문제 정수 리스트 num_list가 주어집니다. 가장 첫 번째 원소를 1번 원소라고 할 때, 홀수 번째 원소들의 합과 짝수 번째 원소들의 합 중 큰 값을 return 하도록 solution 함수를 완성해주세요. 두 값이 같을 경우 그 값을 return합니다. 솔루션 #include #include #include // num_list_len은 배열 num_list의 길이입니다. int solution(int num_list[], size_t num_list_len) { int answer = 0; int sum_o = 0; int sum_e = 0; for(int i = 0; i < num_list_len; i++){ if(i % 2 == 0) sum_e += num_list[i]; else sum_o .. 2023. 8. 1. [프로그래머스/C언어] n개의 간격의 원소들 문제 정수 리스트 num_list와 정수 n이 주어질 때, num_list의 첫 번째 원소부터 마지막 원소까지 n개 간격으로 저장되어있는 원소들을 차례로 담은 리스트를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // num_list_len은 배열 num_list의 길이입니다. int* solution(int num_list[], size_t num_list_len, int n) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(20 * 9 * sizeof(int)); int j = 0; for(int i = 0; i < num_li.. 2023. 8. 1. [프로그래머스/C언어] n번째 원소부터 문제 정수 리스트 num_list와 정수 n이 주어질 때, n 번째 원소부터 마지막 원소까지의 모든 원소를 담은 리스트를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include // num_list_len은 배열 num_list의 길이입니다. int* solution(int num_list[], size_t num_list_len, int n) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(30); int j = 0; for(int i = n - 1; i < num_list_len; i++) answer[j++] = num_list[i]; .. 2023. 8. 1. [프로그래머스/C언어] 카운트 다운 문제 정수 start와 end가 주어질 때, start에서 end까지 1씩 감소하는 수들을 차례로 담은 리스트를 return하도록 solution 함수를 완성해주세요. 솔루션 #include #include #include int* solution(int start, int end) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. int* answer = (int*)malloc(50 * sizeof(int)); int j = 0; for(int i = start; i >= end; i--){ answer[j++] = i; } answer[j] = "\0"; return answer; } https://school.programmers.co.kr.. 2023. 8. 1. [프로그래머스/C언어] 접두사인지 확인하기 문제 어떤 문자열에 대해서 접두사는 특정 인덱스까지의 문자열을 의미합니다. 예를 들어, "banana"의 모든 접두사는 "b", "ba", "ban", "bana", "banan", "banana"입니다. 문자열 my_string과 is_prefix가 주어질 때, is_prefix가 my_string의 접두사라면 1을, 아니면 0을 return 하는 solution 함수를 작성해 주세요. 솔루션 #include #include #include #include // 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요. int solution(const char* my_string, const char* is_prefix) { int answer = 0; int j .. 2023. 8. 1. 이전 1 ··· 23 24 25 26 27 28 29 ··· 34 다음