인사말

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

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

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

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

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

 

 

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

 

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

public class ArrayChecker {
    public static void check(int[] x, int[] y) {
        if(x == y) System.out.print("O");
        else System.out.print("N");
    }

    public static void main(String[] args) {
        int a[] = new int[] {1, 2, 3, 4};
        int b[] = a;
        int c[] = new int[] {1, 2, 3, 4};
        int d[] = new int[] {1, 2, 3, 4, 5};
       
        check(a, b);
        check(b, c);
        check(c, d);
        check(a, d);
    }
}
정답

ONNN

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

public class ArrayComparison {
    public static void check(int[] x, int[] y) {
        if (x == y) System.out.print("O");
        else System.out.print("N");
    }

    public static void main(String[] args) {
        int a[] = {1, 2, 3, 4};
        int b[] = a;
        int c[] = {1, 2, 3, 4};
        int d[] = new int[] {1, 2, 3, 4};
        int e[] = d;
        int f[] = {1, 2, 3};

        check(a, b);
        check(b, c);
        check(c, d);
        check(d, e);
        check(e, f);
    }
}
정답

ONNON

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

public class SubstringCounter {
    public static int countOccurrences(String text, String pattern) {
        int count = 0;
        for (int i = 0; i <= text.length() - pattern.length(); i++) {
            String substring = text.substring(i, i + pattern.length());
            if (substring.equals(pattern)) {
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        String text = "hellosunhellosunshine";
        String pattern1 = "sun";
        String pattern2 = "hello";
        System.out.println("xy" + countOccurrences(text, pattern1));
        System.out.println("ab" + countOccurrences(text, pattern2));
    }
}
정답

xy2
ab2

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

public class ValueSwapper {
    public static void swap(int[] a, int[] b) {
        int temp = a[0];
        a[0] = b[0];
        b[0] = temp;
    }

    public static void main(String[] args) {
        int[] arr1 = {11};
        int[] arr2 = {19};
        swap(arr1, arr2);

        switch (arr1[0]) {
            case 1:
                arr2[0] += 1;
            case 11:
                arr2[0] += 2;
            default:
                arr2[0] += 3;
                break;
        }

        System.out.println(arr1[0] - arr2[0]);
    }
}
정답

5

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

public class StringManipulation {
    public static void func(char[] d, char[] s) {
        int i = 0;
        while (i < s.length && s[i] != '\0') {
            d[i] = s[i];
            i++;
        }
        d[i] = '\0';
    }

    public static void main(String[] args) {
        char[] str1 = "first".toCharArray();
        char[] str2 = new char[50];
        System.arraycopy("teststring".toCharArray(), 0, str2, 0, "teststring".length());

        func(str2, str1);

        int result = 0;
        for (int i = 0; str2[i] != '\0'; i++) {
            result += i;
        }

        System.out.println(result);
    }
}
정답

10

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

interface Calc {
    int calculate(int[] arr, boolean positive);
}

public class Main {
    public static void main(String[] args) {
        int[] numbers = {12, -7, 5, -3, 9, -11, 2, -1, 6, -8};
        PosNegCalc calc = new PosNegCalc();
        System.out.print(calc.calculate(numbers, true) + ", " + calc.calculate(numbers, false));
    }
}

class PosNegCalc implements Calc {
    public int calculate(int[] arr, boolean positive) {
        int sum = 0;
        for (int number : arr) {
            if ((positive && number > 0) || (!positive && number < 0)) {
                sum += number;
            }
        }
        return sum;
    }
}
정답

34, -30

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

public class ArrayManipulation {
    public static void main(String[] args) {
        int[][] arr = {
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        };
        int[] parr1 = arr[1];
        int[] parr2 = arr[2];

        int result = parr2[1] - parr2[2] + parr1[0];

        System.out.println(result);
    }
}
정답

3

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

import java.util.*;


public class UF {
    public static String uniqueChars(String str) {
        boolean[] seen = new boolean[256];
        StringBuilder result = new StringBuilder();
        for (int i = str.length() - 1; i >= 0; i--) {
            char c = str.charAt(i);
            if (!seen[c]) {
                seen[c] = true;
                result.insert(0, c);
            }
        }
        return result.toString();
    }

    public static Map<Character, Integer> charFrequency(String str) {
        Map<Character, Integer> frequencyMap = new LinkedHashMap<>();
        for (char c : str.toCharArray()) {
            frequencyMap.put(c, frequencyMap.getOrDefault(c, 0) + 1);
        }
        return frequencyMap;
    }

    public static void main(String[] args) {
        String str = "abacabcd";
        String unique = uniqueChars(str);
        Map<Character, Integer> frequency = charFrequency(unique);
       
        System.out.println("Unique characters: " + unique);

        for (Map.Entry<Character, Integer> entry : frequency.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}
정답

Unique characters: abcd
a: 1
b: 1
c: 1
d: 1

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

public class LinkedListDemo {

    static class Node {
        int n1;
        Node n2;

        Node(int n1, Node n2) {
            this.n1 = n1;
            this.n2 = n2;
        }
    }

    public static void main(String[] args) {
        Node head = null;
        Node a = new Node(10, null);
        Node b = new Node(25, null);
        Node c = new Node(30, null);
        Node d = new Node(40, null);
       
        head = a;
        a.n2 = b;
        b.n2 = d;
        d.n2 = c;

        System.out.println(head.n2.n2.n1);
    }
}
정답

40

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

public class StringProcessor {
    public static void main(String[] args) {
        String str = "HELLO_WORLD_THIS_IS_JAVA";
        String[] result = str.split("_");
       
        System.out.println("Array length: " + result.length);
        System.out.println("Element at index 2: " + result[2]);
    }
}
정답

Array length: 5
Element at index 2: THIS