Algorithm
-
[백준] 3003번 : 킹, 퀸, 룩, 비숍, 나이트, 폰[JAVA]Algorithm/백준[JAVA] 2022. 12. 25. 03:07
https://www.acmicpc.net/problem/3003 3003번: 킹, 퀸, 룩, 비숍, 나이트, 폰 첫째 줄에 동혁이가 찾은 흰색 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수가 주어진다. 이 값은 0보다 크거나 같고 10보다 작거나 같은 정수이다. www.acmicpc.net # 문제 # 접근방식 원래 들어있는 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수를 입력한 개수와 비교해야하기 때문에 배열을 이용한다. 원래 들어있는 체스들의 개수로 초기화한 chess변수를 선언한다. 동혁이가 찾은 체스들의 개수를 입력할 white변수를 선언한다. for문을 이용하여 원래 체스와 입력한 체스를 하나씩 비교한다. 입력한 체스가 원래 체스의 개수만큼 있다면 출력되는 값은 0이라는 것을 생각한다. if문을 이용..
-
[백준] 18108번 : 1998년생인 내가 태국에서는 2541년생?![JAVA]Algorithm/백준[JAVA] 2022. 12. 25. 03:06
https://www.acmicpc.net/problem/18108 18108번: 1998년생인 내가 태국에서는 2541년생?! ICPC Bangkok Regional에 참가하기 위해 수완나품 국제공항에 막 도착한 팀 레드시프트 일행은 눈을 믿을 수 없었다. 공항의 대형 스크린에 올해가 2562년이라고 적혀 있던 것이었다. 불교 국가인 태국 www.acmicpc.net # 문제 # 접근방식 서기 연도를 저장할 변수 x와 불기 연도를 입력하는 변수 y를 선언한다. 변수 y에 scanner를 할당하여 불기 연도를 입력한다. 서기 연도는 불기 연도보다 543년 더 적기 때문에 불기 연도에서 543을 빼주어 변수 x에 저장한다. 변수 x를 출력하여 불기 연도를 서기 연도로 변환한 결과를 출력한다. # 소스코드 ..
-
[백준] 10926번 : ??![JAVA]Algorithm/백준[JAVA] 2022. 12. 25. 03:03
https://www.acmicpc.net/problem/10926 10926번: ??! 준하는 사이트에 회원가입을 하다가 joonas라는 아이디가 이미 존재하는 것을 보고 놀랐다. 준하는 놀람을 ??!로 표현한다. 준하가 가입하려고 하는 사이트에 이미 존재하는 아이디가 주어졌을 때 www.acmicpc.net # 문제 # 접근방식 아이디(문자열)를 입력할 String타입 변수에 scanner를 할당해준다. 어떤 문자열을 입력해도 입력한 문자열 뒤에 ??!이 출력될 수 있도록 입력받은 문자열에 "??!"문자열을 더해서 출력한다. # 소스코드 # 성능
-
[백준] 10869번 : 사칙연산[JAVA]Algorithm/백준[JAVA] 2022. 12. 25. 03:02
https://www.acmicpc.net/problem/10869 10869번: 사칙연산 두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오. www.acmicpc.net # 문제 # 접근방식 입력을 받기 위해 Scanner를 import 해준다. 피연산자를 입력받을 변수 A, B를 선언해준 뒤, scanner를 할당해준다. 두 변수를 덧셈, 뺄셈, 곱셈, 나눗셈, 나머지 연산해서 출력해준다. # 소스코드 # 성능
-
[백준] 1008번 : A/B[JAVA]Algorithm/백준[JAVA] 2022. 12. 25. 03:01
https://www.acmicpc.net/problem/1008 1008번: A/B 두 정수 A와 B를 입력받은 다음, A/B를 출력하는 프로그램을 작성하시오. www.acmicpc.net # 문제 # 접근방식 아주 간단한 문제라고 생각한다. Scanner를 이용하기 위해 import java.util.Scanner를 사용한다. 두 개의 정수 입력을 위해 정수타입 변수 A, B를 선언하여 각각의 변수에 스캐너 객체를 할당하여 입력받는다. System.out.println()를 이용하여 두 개의 변수를 더해서 출력한다. # 소스코드 # 성능