본문 바로가기
정보처리기사 실기

[정보처리기사 실기] 2020년 기출 프로그래밍 언어 활용 문제 분석

by Devinus 2021. 4. 19.

2020년 정보처리기사 실기 프로그래밍 언어 문제 분석

 

- 2020년 1회차 프로그래밍 문제 (3문제)

 

1. [C] 버블 벙렬 오름차순 - 출력 결과 작성

#include <stdio.h>
    void align(int a[ ]) {
    int temp;
    for (int i = 0; i < 4; i++) for (int j=0; j < 4 - i; j++) 
    if (a[j]> a[j+1]) {
        temp = a[j];
        a[j] = a[j+1];
        a[j+1] = temp;
        }
             }

        main( ) {
        int a[ ] = { 85, 75, 50, 100, 95 };
        align(a);
        for (int i = 0; i < 5; i++) printf("%d ", a[i]);
    }
더보기
정답: 50, 75, 85, 95, 100

 

2. [Java] 배열 - 출력 결과 작성

public class Test {
    static int[] arr() {
        int a[] = new int[4];
        int b = a.length;
        for(int i = 0; i < b; i++)
            a[i] = i;
        return a;
    }

    public static void main(String[] args) {
        int a[] = arr();
        for(int i = 0; i < a.length; i++)
            System.out.print(a[i] + " ");
    }
더보기
정답: 0 1 2 3

 

3. [C] switch, case문 - 출력 결과 작성

#include <stdio.h>
  main( ) {
    int c = 1;
    switch (3) {
      case 1: c += 3;
      case 2: c++;
      case 3: c = 0;
      case 4: c += 3;
      case 5: c -= 10;
      default: c--;
    }
    printf("%d", c);
}
더보기
정답: -8

 

- 2020년 2회차 프로그래밍 문제 (3문제)

 

1. [Python] 집합 - 출력 내용 작성

asia={'한국', '중국', '일본'}
asia.add('베트남')
asia.add('중국')
asia.remove('일본')
asia.update(['홍콩', '한국', '태국'])
print(asia)
더보기
정답: {'한국', '중국', '베트남', '홍콩', '태국'}

해설:
asia = {'한국', '중국', '일본'} -- 파이썬에서 {값1, 값2, 값3}과 같이 정의된 것은 집합(set)이다.
-- 파이썬에서 집합은 중복된 값은 제거하여 저장한다.
asia.add('베트남') -- asia는 집합객체이며 집합객체.add(값)은 집합에 값을 추가한다.
-- 집합의 특성상 이미 존재하는 값이라면 추가로 저장되지 않는다.
asia.remove('일본') -- 집합객체.remove(값)은 집합에서 값을 제거한다.
>>> a = {1, 2, 3}
>>> a.remove(4)
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    a.remove(4)
KeyError: 4

# 집합에 존재하지 않는 값을 remove()로 제거하려 할 경우 KeyError를 발생시킨다.​


asia.update(['홍콩', '한국', '태국']) -- 집합객체.update(iterable)은 iterable(반복되는 Ex. List, Tuple, Set, Dictionary 등)객체를 집합에 추가한다.

>>> a = {1,2,3}
>>> a.update([3,4,5])
>>> a
{1, 2, 3, 4, 5}
>>> a = {1, 2, 3}

>>> a.update(4)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    a.update(4)
TypeError: 'int' object is not iterable

# update()안에 iterable한 값을 넣지 않고 literal(Ex. 숫자 1)한 값을 넣을 경우 에러를 방생시킨다.

 

2. [Java] 생성자 - 빈칸 채우기

class Parent {
	void show() {
    	System.out.println("parent");
    }
}

class Child extends Parent {
	void show() {
    	System.out.println("child");
    }
}

public class Test {
	public static void main(String[] args) {
    	Parent pa = (①) Child();
        pa.show();
    }
}

// 출력결과 Child
더보기
정답: ① new

 

3. [Java] 상속 - 출력 결과 작성

class A {
    int a;
    public A(int a) { 
    	this.a = a;
    }
    void display() {
    	System.out.println("a=" + a);
    }
}
class B extends A {
	public B(int b) {
    	super(a);
        super.display();
    }
}
public class Test {
	public static void main(String[] args) {
    	B obj = new B(10);
    }
}
더보기
정답: a = 10

 

- 2020년 3회차 프로그래밍 문제 (4문제)

 

1. [C] while문 - 출력 결과 작성

int main() {
    int i, c = 0;
    while (i < 10) {
    	i++;
        c *= i;
    }
    printf("%d", c);
}
더보기
정답: 0

 

2. [C] - 출력 결과 작성

int r1() {
	return 4;
}

int r10() {
	reuturn (30 + r1());
}

int r100() {
	return (200 + r10());
}

int main() {
  printf("%d ", r100());
  return 0;
}
더보기
정답: 234

해설:
python 코드
def r1():
	return 4

def r10():
	return 30 + r1()

def r100():
	return 200 + r10()

print('%d' %r100())​


python 코드 실행 결과
234

 

3. [Java] while문, if문 - 출력 결과 작성

public class Gisafirst {
	public static void main(String[] args) {
    	int i = 0;
        int sum = 0;
    	while( i < 10 ) {
            i++;
            if(i % 2 == 1)
                continue;
            sum += i;
        }
    	System.out.println(sum);
    }
}
더보기
정답: 30

해설: 
python 코드 
i = 0
s = 0
while i < 10:
	i += 1
	if i % 2 == 1:
		continue
	s += i
	print(f'i = {i}, s = {s}')
print(s)


python 코드 실행 결과
i = 2, s = 2
i = 4, s = 6
i = 6, s = 12
i = 8, s = 20
i = 10, s = 30
30

 

4. [Java] 상속 - 출력 결과 작성

abstract class Vehicle() {
	String name;
   
   	abstract public String getName(String val);
    
    public String getName() {
    	return "Vehicle name: " + name;
    }
}

class Car extends Vehicle() {
	public Car(String val) {
    	name = super.name = val;
    }
    
    public String getName(String val) {
    	return "Car name: " + val;
    }
    
    public String getName(byte val[]) {
    	return "Car name: " + val;
    }
}

public class Test() {
	public static void main(String[] args) {
    	Vehicle obj = new Car("Spark");
        
        System.out.println(obj.getName());
    }
}
더보기
정답: Vehicle name: Spark

 

- 2020년 4, 5회차 프로그래밍 문제 (5문제)

 

1. [Java] 배열 - 빈칸 채우기

public class Gisafirst { 
   public static void main(String[] args) {   

     int[][] array = new int[①][②];

    int n = 1;

    for(int i = 0; i < 3; i++) {

      for(int j = 0; j < 5; j++) {

        array[i][j] = j*3 + (i+1);

        System.out.print(array[i][j] + "");

      }

      System.out.println();

    }

  }

}

// 출력 결과
// 1 4 7 10 13
// 2 5 8 11 14
// 3 6 9 12 15
더보기
정답: ① 3 ② 5

 

2. [Python] 중첩 리스트, for문 - 출력 결과 작성

lol = [[1,2,3], [4,5], [6,7,8,9]]

print(lol[0])

print(lol[2][1])

for sub in lol:
  for item in sub:
    print(item, end="")
  print()
더보기
정답: 
[1, 2, 3]
7
123
45
6789

해설:
python 코드
lol = [[1,2,3], [4,5], [6,7,8,9]]

print(lol[0])

print(lol[2][1])

for sub in lol:
  for item in sub:
    print(item, end="")
  print()
​

 

python 코드 실행 결과

[1, 2, 3]
7
123
45
6789

 

3. [C] 문자열, 포인터 - 출력 결과 작성

int main(){
    char *p = "KOREA";
    printf("%s ", p);
    printf("%s ", p+3);
    printf("%c ", *p);
    printf("%c ", *(p+3));
    printf("%c ", *p+2);
}
더보기
정답:
KOREA
EA
K
E
M

 

4. 진수 변환(10진수 -> 2진수), while문, for문 - 빈칸 채우기

public class Gisafirst { 
   public static void main(String[] args) {   
      int a[] = new int[8];
      int i = 0, n = 10;
      while (①) {  
         a[i++] = ②; 
         n /= 2; 
      } 
      for (i=7; i>=0; i--)
         System.out.printf("%d", a[i]);
      }
}
더보기
정답: ① n > 0 ② n % 2

해설:
python 코드
a = [0] * 8
print(a)
i = 0
n = 10
while n > 0:
    a[i] = n % 2
    print(f'a[i] = {a[i]}, i = {i} , n = {n}')
    i += 1
    n //= 2
for i in range(7, -1, -1):
    print(a[i], end='')


python 코드 실행 결과
[0, 0, 0, 0, 0, 0, 0, 0]
a[i] = 0, i = 0 , n = 10
a[i] = 1, i = 1 , n = 5
a[i] = 0, i = 2 , n = 2
a[i] = 1, i = 3 , n = 1
00001010

 

5. [Java] 상속 - 출력 결과 작성

class Parent {
 int compute(int num) {
    if( num <= 1) return num;
        return compute(num-1) + compute(num-2);
    }
}

class Child extends Parent {
 int compute(int num) {
    if( num <= 1) return num;
    return compute(num-1) + compute(num-3);
    }
}

public class Gisafirst {
 public static void main(String[] args) {
     Parent obj = new Child();
        System.out.print(obj.compute(4));
    }
}
더보기
정답: 1