[BOJ] 3003

Organ·2023년 9월 19일
0

[문제 풀이]

목록 보기
39/123

킹, 퀸, 룩, 비숍, 나이트, 폰

문제

내 풀이

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);

		int[] arr  = {1, 1, 2, 2, 2, 8};
		int[] arr2 = new int[6];

		for(int i = 0; i < arr.length; i++)
		{
			arr2[i] = sc.nextInt();
			arr2[i] = arr[i] - arr2[i];
		}

		for(int i : arr2)
			System.out.printf("%d ", i);
	}
}

다른 풀이

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int king = 1;
		int queen = 1;
		int rook = 2;
		int bishop = 2;
		int knight = 2;
		int pawn = 8;
		
		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		king = king - Integer.parseInt(st.nextToken());
		queen = queen - Integer.parseInt(st.nextToken());
		rook = rook - Integer.parseInt(st.nextToken());
		bishop = bishop - Integer.parseInt(st.nextToken());
		knight = knight - Integer.parseInt(st.nextToken());
		pawn = pawn - Integer.parseInt(st.nextToken());
 
		System.out.print(king + " ");
		System.out.print(queen + " ");
		System.out.print(rook + " ");
		System.out.print(bishop + " ");
		System.out.print(knight + " ");
		System.out.print(pawn + " ");		
		
	}
}

정리

StringTokenizer 쓰기 귀찮아서 Scanner썼는데 느리긴 느리다.

출처

https://st-lab.tistory.com/297

0개의 댓글