백준 알고리즘

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); if((year % 4 == 0) && (year % 100 != 0)) { System.out.println("1"); } else if(year % 400 == 0) { System.out.println("1"); } else { System.out.println("0"); } } } 설명 위 문제는 Scanner를 통해 정수(연도)를 사용자에게 입력받은 뒤 그 해가 연도인지 if문을 통해 결과를 얻는 문제이다. 문제에서 윤년은 연도가 4..
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //계산할 수 두개를 입력받음 int num1 = sc.nextInt(); int num2 = sc.nextInt(); //곱하는 수(num2)의 1의 자릿수를 구하여 c1에 저장 int c1 = (num2 % 100) % 10; //3,4,5에 들어갈 숫자를 저장하는 배열 생성 int[] result = new int[3]; //(3)에 들어갈 num1과 num2의 일의 자릿수를 곱한 값을 저장 result[0] = num1 * c1; //곱하는 수(num2)의 10의 자릿수를 구하여 c2에 저장 int c2 = (num2 % 1..
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(); 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); } } 설명 위 문제는 a,b,c라는 세개의 값을 사용자에게 입력 받은 뒤, 문제에서 제시한 대로 네 가지의 경우를 계산하여 출력하면 ..
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int y = sc.nextInt(); y -= 543; System.out.println(y); } } 설명 위 문제는 Scanner를 통해 사용자에게 값을 입력 받고, 그 입력받은 값에서 543을 빼준 뒤 출력하는 간단한 문제이다. 불기 연도와 서기 연도 계산법을 구글링해보면 쉽게 풀이할 수 있는 문제이다.
빡수수
'백준 알고리즘' 카테고리의 글 목록 (2 Page)