인사말

안녕하세요. 이 글을 읽고 계신다면 정보처리기사 또는 정보처리산업기사 수험생이실 것 같습니다.

여러 좋은 서적에서 이론을 잘 설명하고 있지만, 코딩 문제의 경우 같은 문제를 여러 번 풀다 보면 답이 머리에 기억되어 새로운 문제가 필요하게 되는 순간이 옵니다.

그럴 때 더 많은 문제를 풀어보고 도움이 되게 하고자 여러 C언어, JAVA, Python 문제를 변형 시키고 직접 컴파일하여 답을 확인하면서 문제를 만들었습니다.

정보처리 실기를 공부하시는 모든 수험생 여러분, 목표하는 모든 것이 이루어지는 그날까지 응원하겠습니다. 화이팅!

목표를 향해 열심히 노력하시고, 좋은 결과 있기를 기원합니다!

 

 

정보처리기사 실기 언어 코딩 기출변형 문제

 

1. 출력 값을 작성하시오.

#include <stdio.h>
#include <stdbool.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

bool arrays_equal(int arr1[], int size1, int arr2[], int size2) {
    if (size1 != size2) {
        return false;
    }
    for (int i = 0; i < size1; i++) {
        if (arr1[i] != arr2[i]) {
            return false;
        }
    }
    return true;
}

void check(int arr1[], int size1, int arr2[], int size2) {
    if (arrays_equal(arr1, size1, arr2, size2)) {
        printf("X");
    } else {
        printf("Y");
    }
}

int main() {
    int a[] = {1, 2, 3, 5};  // Changed last element
    int b[] = {1, 2, 3, 4};
    int c[] = {1, 2, 3};

    int size_a = ARRAY_SIZE(a);
    int size_b = ARRAY_SIZE(b);
    int size_c = ARRAY_SIZE(c);

    check(a, size_a, b, size_b);
    check(b, size_b, c, size_c);
    check(a, size_a, c, size_c);

    return 0;
}
정답

YYY

2. 출력 값을 작성하시오.

#include <stdio.h>
#include <string.h>

int cnt(const char* str, const char* p) {
    int result = 0;
    int str_len = strlen(str);
    int p_len = strlen(p);

    for (int i = 0; i <= str_len - p_len; i++) {
        int match = 1;
        for (int j = 0; j < p_len; j++) {
            if (str[i + j] != p[j]) {
                match = 0;
                break;
            }
        }
        if (match) {
            result++;
        }
    }
    return result;
}

int main() {
    const char* str = "abdcabcabca";
    const char* p1 = "ca";
    const char* p2 = "ab";

    printf("ab%d ca%d\n", cnt(str, p1), cnt(str, p2));

    return 0;
}
정답

ab3 ca3

3. 출력 값을 작성하시오.

#include <stdio.h>

void swap(int x, int y) {
    int temp = x;
    x = y;
    y = temp;
}

int main() {
    int x = 5;
    int y = 15;
    swap(x, y);

    switch(x) {
        case 0:
            y -= 2;
        case 5:
            y -= 4;
        case 15:
            y -= 8;
            break;
        default:
            y -= 6;
            break;
    }

    printf("%d", x - y);
    return 0;
}
정답

2

4. 출력 값을 작성하시오.

#include <stdio.h>

void func(char *d, const char *s) {
    while (*s) {
        *d = *s;
        d++;
        s++;
    }
    *d = '\1';
}

int main() {
    const char* source = "test";
    char destination[50] = "initial";
    int total = 0;

    func(destination, source);

    for (int idx = 0; destination[idx] != '\1'; ++idx) {
        total += (idx + 2) * 2;
    }

    printf("%d", total);
    return 0;
}
정답

28

5. 출력 값을 작성하시오.

#include <stdio.h>

int main() {
    int array1[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int array2[3][3] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
    int* ptrArray[2] = {array1[1], array2[2]};
   
    printf("%d", ptrArray[0][2] + *(ptrArray[0] + 1) + **(ptrArray + 1));
    return 0;
}
정답

14

6. 출력 값을 작성하시오.

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

void rf(const char *str, int index, bool *seen, char *result) {
    if (index < 0) return;
    char c = str[index];
    rf(str, index - 1, seen, result);
    if (!seen[(unsigned char)c]) {
        seen[(unsigned char)c] = true;
        int len = strlen(result);
        result[len] = c;
        result[len + 1] = '\0';
    }
}

int main() {
    const char *str = "abacabcd";
    int length = strlen(str);
    bool seen[256] = {false};
    char result[256] = {0};

    rf(str, length - 1, seen, result);

    printf("%s\n", result);
    return 0;
}
정답

abcd

7. 출력 값을 작성하시오.

#include <stdio.h>

struct node {
    int value;
    struct node *next;
};

int main() {
    struct node a = {100, NULL};
    struct node b = {200, NULL};
    struct node c = {300, NULL};
    struct node *ptr_head = &b;

    a.next = &b;
    b.next = &c;
    c.next = &a;

    printf("%d", ptr_head->next->value);

    return 0;
}
정답

300

8. 출력 값을 작성하시오.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX_STR_LEN 100
#define MAX_PARTS 10

void splitString(const char* str, char delimiter, char result[][MAX_STR_LEN], int* count) {
    const char* start = str;
    const char* end;
    *count = 0;
   
    while ((end = strchr(start, delimiter)) != NULL) {
        size_t len = end - start;
        strncpy(result[*count], start, len);
        result[*count][len] = '\0';
        (*count)++;
        start = end + 1;
    }
   
    strcpy(result[*count], start);
    (*count)++;
}

int main() {
    const char* str = "ITISTESTSTRING";
    char result[MAX_PARTS][MAX_STR_LEN];
    int count = 0;
   
    splitString(str, 'T', result, &count);
   
    if (count > 3) {
        printf("%s\n", result[3]);
    } else {
        printf("Index out of bounds\n");
    }
   
    return 0;
}
정답

S

9. 출력 값을 작성하시오.

#include <stdio.h>

#define SIZE 5

void addArrays(const int *a, const int *b, int *c, int size) {
    for (int i = 0; i < size; i++) {
        c[i] = a[i] + b[i];
    }
}

void incrementArray(int *arr, int size, int value) {
    for (int i = 0; i < size; i++) {
        arr[i] += value;
    }
}

void printArray(const int *arr, int size) {
    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
}

int main() {
    int A[SIZE] = {1, 2, 3, 4, 5};
    int B[SIZE] = {5, 4, 3, 2, 1};
    int C[SIZE] = {0};

    addArrays(A, B, C, SIZE);
    incrementArray(C, SIZE, 10);

    printArray(C, SIZE);

    return 0;
}
정답

16 16 16 16 16

10. 출력 값을 작성하시오.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    char name[30];
    int age;
} Person;

int comparePersons(const void *a, const void *b) {
    const Person *personA = (const Person *)a;
    const Person *personB = (const Person *)b;

    if (personA->age != personB->age) {
        return personA->age - personB->age;
    }
    return strcmp(personA->name, personB->name);
}

int main() {
    int num_people = 3;
    Person *people = (Person *)malloc(num_people * sizeof(Person));

    if (people == NULL) {
        fprintf(stderr, "Memory allocation failed\n");
        return 1;
    }

    strcpy(people[0].name, "Alice");
    people[0].age = 30;
    strcpy(people[1].name, "Bob");
    people[1].age = 25;
    strcpy(people[2].name, "Charlie");
    people[2].age = 25;

    qsort(people, num_people, sizeof(Person), comparePersons);

    for (int i = 0; i < num_people; i++) {
        printf("Name: %s, Age: %d\n", people[i].name, people[i].age);
    }

    free(people);

    return 0;
}
정답

Name: Bob, Age: 25
Name: Charlie, Age: 25
Name: Alice, Age: 30