Algorithm

[백준] 2. 조건문 - 2753. 윤년 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); sc.close(); // 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. if(year%4 == 0 && (year % 100 != 0 || year % 400 == 0)) { System.out.println(1); } else { System.out.println(0); } } } 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. 기본으로 먼저 4의 배수인지 판단 ..

[백준] 2. 조건문 - 9498. 시험 성적 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int score = sc.nextInt(); sc.close(); if (score >= 90) { System.out.println("A"); } else if (score >= 80) { System.out.println("B"); } else if (score >= 70) { System.out.println("C"); } else if (score >= 60) { System.out.println("D"); } else { System.out.println("F");..

[백준] 2. 조건문 - 1330. 두 수 비교하기 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); if (a > b) { System.out.println(">"); } else if (a < b) { System.out.println("

[백준] 1. 입출력과 사칙연산 - 2588. 곱셈 (Java11)
문제 풀이 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); sc.close(); System.out.println(a*(b%10)); System.out.println(a*(b%100/10)); System.out.println(a*(b/100)); System.out.println(a*b); } } 이 문제의 포인트는 b에 들어오는 입력값의 각 자리수를 얻어와서 a와 곱해주는 것이다. 일의 자리 5의 경우 385%10을 해주면 10으로 나눠준 값 나머지인 ..

[백준] 1. 입출력과 사칙연산 - 10430. 나머지 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt(); sc.close(); System.out.println((A + B) % C); System.out.println((A % C + B % C) % C); System.out.println((A * B) % C); System.out.println((A % C * B % C) % C); } } Scanner 객체를 생성하여 입력 받고 네 가지 값을 순서대로 출력..

[백준] 1. 입출력과 사칙연산 - 3003. 킹, 퀸, 룩, 비숍, 나이트, 폰 (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int king = 1; int queen = 1; int rook = 2; int bishop = 2; int knight = 2; int pawn = 8; king = king - sc.nextInt(); queen = queen - sc.nextInt(); rook = rook - sc.nextInt(); bishop = bishop - sc.nextInt(); knight = knight - sc.nextInt(); pawn = pawn - sc.nextInt(); s..

[백준] 1. 입출력과 사칙연산 - 18108. 1998년생인 내가 태국에서는 2541년생?! (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); sc.close(); System.out.println(year-543); } } 불기 연도가 주어질 때 이를 서기 연도로 바꾸어 출력하라는 것이다. 1998년생의 경우 불기로는 2541년생이라는 것이다. 즉, 서기와 불기는 543년 차이가 있음을 알 수 있다. 주어지는 불기 연도에 543년을 빼주는 값이 서기이다! 출처 https://www.acmicpc.net/problem/18108 18108번: 1998년생인 내가 태국에서는..

[백준] 1. 입출력과 사칙연산 - 10926. ??! (Java11)
문제 풀이 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String id = sc.next(); sc.close(); System.out.println(id + "??!"); } } 처음엔 조건문으로 풀어야 하는 줄 알았는데 그냥 간단하게 뒤에 ??!만 추가해서 출력하면 되는 문제였다! 출처 https://www.acmicpc.net/problem/10926 10926번: ??! 준하는 사이트에 회원가입을 하다가 joonas라는 아이디가 이미 존재하는 것을 보고 놀랐다. 준하는 놀람을 ??!로 표현한다. 준하가 가입하려고 하는 사..