[Java] SWEA 거듭 제곱 & 암호생성기

Lee GaEun·2025년 5월 7일

[Java] 알고리즘

목록 보기
72/93

1217 거듭 제곱 문제 링크

#1

3분


import java.util.HashMap;
import java.util.Scanner;
import java.io.FileInputStream;
import java.util.Set;

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();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int answer = 1;
            for(int i=0; i<y; i++) {
                answer *= x;
            }

            System.out.println("#"+test_case+" "+answer);
        }
    }
}


1225 암호생성기 문제 링크

#1

9분


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();
            Deque<Integer> arr = new ArrayDeque<>();
            for(int i=0; i<8; i++) {
                arr.addLast(sc.nextInt());
            }

            int now;
            int index = 1;
            while (true) {
                if(index>5) index = 1;
                now = arr.pollFirst();
                if(now-index <= 0) {
                    arr.addLast(0);
                    break;
                }
                arr.addLast(now-index);
                index++;
            }

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

profile
I will give it my all (๑•̀o•́๑)ง

0개의 댓글