[Java] SWEA 암호문1~3

Lee GaEun·2025년 5월 7일

[Java] 알고리즘

목록 보기
73/93

1228 암호문1 문제 링크

#1

15분


import java.util.*;
import java.io.FileInputStream;

class Solution
{
    static char[][] arr;
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int T;
        T=10;

        for(int test_case = 1; test_case <= T; test_case++)
        {
            int N = sc.nextInt();
            LinkedList<Integer> arr = new LinkedList<>();
            for(int i=0; i<N; i++) {
                arr.addLast(sc.nextInt());
            }

            int comNum = sc.nextInt();
            for(int j=0; j<comNum; j++) {
                String commend = sc.next();
                int index = sc.nextInt();
                int count = sc.nextInt();
                for (int i = 0; i < count; i++) {
                    arr.add(index+i, sc.nextInt());
                }
            }

            System.out.print("#" + test_case + " ");
            for(int i=0; i<10; i++) {
                System.out.print(arr.get(i)+" ");
            }
            System.out.println();
        }
    }
}

  • 앞의 암호 10개 항만 출력하라는 글을 못 봐서 좀 걸림
  • 문제를 꼼꼼히 읽어야 되는데 시간을 생각하다보니 잘 안됨

1229 암호문2 문제 링크

#1

4분


import java.util.*;
import java.io.FileInputStream;

class Solution
{
    static char[][] arr;
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int T;
        T=10;

        for(int test_case = 1; test_case <= T; test_case++)
        {
            int N = sc.nextInt();
            LinkedList<Integer> arr = new LinkedList<>();
            for(int i=0; i<N; i++) {
                arr.addLast(sc.nextInt());
            }

            int comNum = sc.nextInt();
            for(int j=0; j<comNum; j++) {
                String commend = sc.next();
                int index = sc.nextInt();
                int count = sc.nextInt();

                if(commend.equals("I")) {
                    for (int i = 0; i < count; i++) {
                        arr.add(index+i, sc.nextInt());
                    }
                }
                else if(commend.equals("D")) {
                    for(int i=0; i<count; i++) {
                        arr.remove(index);
                    }
                }

            }

            System.out.print("#" + test_case + " ");
            for(int i=0; i<10; i++) {
                System.out.print(arr.get(i)+" ");
            }
            System.out.println();
        }
    }
}

  • 위에 만들었던 코드에 delete 기능만 추가하는 거라 금방 함

1230 암호문3 문제 링크

#1

2분


import java.util.*;
import java.io.FileInputStream;

class Solution
{
    static char[][] arr;
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int T;
        T=10;

        for(int test_case = 1; test_case <= T; test_case++)
        {
            int N = sc.nextInt();
            LinkedList<Integer> arr = new LinkedList<>();
            for(int i=0; i<N; i++) {
                arr.addLast(sc.nextInt());
            }

            int comNum = sc.nextInt();
            for(int j=0; j<comNum; j++) {
                String commend = sc.next();
                int index = sc.nextInt();

                if(commend.equals("I")) {
                    int count = sc.nextInt();
                    for (int i = 0; i < count; i++) {
                        arr.add(index+i, sc.nextInt());
                    }
                }
                else if(commend.equals("D")) {
                    int count = sc.nextInt();
                    for(int i=0; i<count; i++) {
                        arr.remove(index);
                    }
                }
                else if(commend.equals("A")) {
                    for(int i=0; i<index; i++) {
                        arr.addLast(sc.nextInt());
                    }
                }

            }

            System.out.print("#" + test_case + " ");
            for(int i=0; i<10; i++) {
                System.out.print(arr.get(i)+" ");
            }
            System.out.println();
        }
    }
}

  • 이것도 이전 코드에서 Add 기능 추가한 거
profile
I will give it my all (๑•̀o•́๑)ง

0개의 댓글