공지사항

2025년 정보처리기사 실기 가답안 모범 답안

https://docs.google.com/spreadsheets/d/1Hzq4jTvyEvFnkeG1xIRrKf0reQEKdgiGZAf-mCbZuqE/edit?usp=sharing



번호분류문제답안
1세션을 가로채다.' 라는 의미로, 정당한 사용자의 세션 상태를 훔치거나 도용하여 액세스하는 보안 공격 기법이다. TCP ( )은(는) 클라이언트/서버 간 TCP 세션으로 통신 중일 때 RST 패킷을 보내어 일시적으로 희생자의 세션을 끊고 공격자에게 서버와의 연결을 재설정하는 보안 공격이다.세션 하이재킹(Session Hijacking)
2무결성의 종류도메인, 개체, 참조
3오류 검출 코드CRC
4겁주는 공격 (보기에서 선택)스캐어웨어(Scareware)
5JAVA예외 처리
public class Kisa {
public static void main(String[] args) {
int a=5,b=0;
try{
System.out.print(a/b);
}
catch(ArithmeticException e){
System.out.print("출력1");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.print("출력2");
}

catch (NumberFormatException e) {
System.out.print("출력3");
}

catch(Exception e){
System.out.print("출력4");
}

finally{
System.out.print("출력5");
}
}
}
출력1 출력5
6MAC <-> IPARP, RARP
7SQLName | incentive
이순신 | 1000
8ㄷ.degree, ㅁ.cardinality, ㅅ.foreign, ㄱ.domain
9Subnetㄱ,ㄴ,ㄷ,ㄹ,ㅁ
10CC 추가 후 정렬
#include <stdio.h>

char Data[5] = {'B', 'A', 'D', 'E', '\0'}; // 5번째 요소 추가
char c;

int main() {
int i, temp, temp2;
c = 'C'; // 세미콜론 추가

printf("%d ", Data[3] - Data[1]); // E - A = 69 - 65 = 4

for(i = 0; i < 5; ++i) {
if(Data[i] > c)
break;
}

temp = Data[i];
Data[i] = c;
i++;

for(; i < 5; ++i) {
temp2 = Data[i];
Data[i] = temp;
temp = temp2;
}

for(i = 0; i < 5; i++) {
printf("%c", Data[i]);
}

printf("\n"); // 줄바꿈 추가

return 0; // 반환값 추가
}
4

BACDE
11C배열, malloc
#include <stdio.h>
#include <stdlib.h>

int main() {
// 동적 메모리 할당으로 정수 배열 생성
int *arr = (int*)malloc(5 * sizeof(int));

// 메모리 할당 확인
if (arr == NULL) {
printf("메모리 할당 실패\n");
return 1;
}

// 배열에 값 할당
arr[0] = 5;
arr[1] = 8;

// 배열의 값을 더해서 13 출력
int sum = arr[0] + arr[1];
printf("%d\n", sum);

// 할당된 메모리 해제
free(arr);

return 0;
}
13
12결합도 종류에 해당하는 기호를 쓰시오.

① 다른 모듈 내부에 있는 변수나 기능을 다른 모듈에서 사용하는 경우

② 모듈 간의 인터페이스로 배열이나 오브젝트(Object), 자료구조(Structure) 등이 전달되는 경우

③ 파라미터가 아닌 모듈 밖에서 선언되어 있는 전역 변수를 참조하고 전역 변수를 갱신하는 식으로 상호 작용하는 경우

ㄱ. 자료 결합도 ㄴ. 스탬프 결합도 ㄷ. 제어 결합도

ㄹ. 공통 결합도 ㅁ. 내용 결합도 ㅂ. 외부 결합도
① ㅁ ② ㄴ ③ ㄹ
13JAVAclass Parent {
static int total = 0; // 정적 변수 초기화
int v = 1; // 인스턴스 변수 초기화

public Parent() {
total += (++v); // v는 2가 되고, total += 2 실행 (total = 0 + 2 = 2)
show(); // 부모 클래스의 show() 호출, Child 객체가 생성될 때는 오버라이드된 show() 호출
}

public void show() {
total += total; // total = total + total (total = 2 + 2 = 4)
}
}

class Child extends Parent {
int v = 10; // Child의 인스턴스 변수 v 초기화 (Parent의 v와 별개)

public Child() {
// 여기서 먼저 Parent() 생성자가 호출됨 (total = 4)
v += 2; // Child의 v는 12가 됨
total += v++; // total += 12 (total = 4 + 12 = 16), 그 후 v는 13이 됨
show(); // 오버라이드된 show() 호출
}

@Override
public void show() {
total += total * 2; // total = total + (total * 2) (total = 16 + (16 * 2) = 16 + 32 = 48)
}
}

public class Kisa {
public static void main(String[] args) {
new Child(); // Child 객체 생성
System.out.println(Parent.total); // Parent.total 출력 (54)
}
}
54
14래퍼(wrapper) 패턴, 서로 다른 인터페이스끼리 연결adapter
15
16JAVApublic class Kisa {
public static void main(String[] args) {
int[] data = {3, 5, 8, 12, 17};
System.out.println(func(data, 0, data.length - 1));
}

static int func(int[] a, int st, int end) {
if (st >= end) return 0;
int mid = (st + end) / 2;
return a[mid] + Math.max(func(a, st, mid), func(a, mid + 1, end));
}
}
20
17Pythonclass Node:
def __init__(self, value):
self.value = value
self.children = []

def tree(li):
nodes = [Node(i) for i in li]
for i in range(1, len(li)):
nodes[(i - 1) // 2].children.append(nodes[i])
return nodes[0]

def calc(node, level=0):
if node is None:
return 0
return (node.value if level % 2 == 1 else 0) + sum(calc(n, level + 1) for n in node.children)

li = [3, 5, 8, 12, 15, 18, 21]
root = tree(li)

print(calc(root))
13
18C연결 리스트(head 5 4 3 2 1 순으로 연결 - 리커넥트를 하면 3을 앞으로 가져와서 연결 35421)
#include <stdio.h>
#include <stdlib.h>

typedef struct Data {
int value;
struct Data *next;
} Data;

Data* insert(Data* head, int value) {
Data* new_node = (Data*)malloc(sizeof(Data));
if (new_node == NULL) {
printf("메모리 할당 실패\n");
exit(1);
}
new_node->value = value;
new_node->next = head;
return new_node;
}

Data* reconnect(Data* head, int value) {
if (head == NULL || head->value == value) return head;

Data *prev = NULL, *curr = head;
while (curr != NULL && curr->value != value) {
prev = curr;
curr = curr->next;
}

if (curr != NULL && prev != NULL) {
prev->next = curr->next;
curr->next = head;
head = curr;
}
return head;
}

int main() {
Data *head = NULL, *curr;

// 5부터 1까지 역순으로 연결 리스트 생성
for (int i = 1; i <= 5; i++)
head = insert(head, i);

// 값이 3인 노드를 찾아 리스트의 맨 앞으로 이동
head = reconnect(head, 3);

// 연결 리스트 출력
for (curr = head; curr != NULL; curr = curr->next)
printf("%d", curr->value);
printf("\n");

// 메모리 해제 (추가)
while (head != NULL) {
Data* temp = head;
head = head->next;
free(temp);
}

return 0;
}
35421
1916진수908
20JAVApublic class Kisa {
public static void main(String[] args) {
System.out.println(calc("5"));
}

// int 매개변수를 받는 calc 메소드 (피보나치 수열 계산)
static int calc(int value) {
if (value <= 1) return value;
return calc(value - 1) + calc(value - 2);
}

// String 매개변수를 받는 calc 메소드 (변형된 피보나치)
static int calc(String str) {
int value = Integer.valueOf(str);
if (value <= 1) return value;
return calc(value - 1) + calc(value - 3);
}
}
4