본문 바로가기

반응형

알고리즘/백준

(111)
[백준] 8393 - 합 import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n, sum=0; n = sc.nextInt(); for(int i=1;i
[백준] 10950 - A + B(3) T에 입력한 숫자만큼 A와 B를 반복해서 돌리는 문제다. import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t; t = sc.nextInt(); int[] a = new int[t]; int[] b = new int[t]; for(int i=0; i
[백준] 2739 - 구구단 조건문 단계를 무사히 마치고 반복문 단계로 진입했다! 이 문제 역시 반복문 하면 빠지지 않고 나오는 예제다. Scanner 클래스를 이용한 방법과 BufferedReader를 이용한 방법 2가지로 풀어봤다. 1. Scanner 클래스를 이용한 방법 import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n; n = sc.nextInt(); for(int i=1;i
[백준] 2480 - 주사위 세 개 원래는 삼항연산자로 도전해보려고 했다가 쉽지않아서 일일히 비교하는 방법으로 바꿨는데 자꾸 틀려서 한참 고민했던 문제다.. 조건을 많이 쓰다보니 빼먹어서 틀렸던 거 같다. 조금 더 수정하니 성공했다. import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a, b, c, money, max; a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); sc. close(); if(((a == b) && (a == c) && (b == c))){ money = 10000+(a)*1000; System.out.prin..
[백준] 2525 - 오븐 시계 이전에 풀었던 문제인 알람 시계와는 다르게 이번에는 입력 시각에 시간을 더하는 문제다. import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int h, m, oven; h = sc.nextInt(); m = sc.nextInt(); oven = sc.nextInt(); //현재 분과 오븐 시간이 60 이상일 때 if((m+oven)> 59){ //분과 오븐 시간을 더한 뒤, 60으로 나눈 몫을 현재 시에 더해줌. h += (m+oven)/60; m += oven; //m을 60으로 나눈 나머지가 분이 된다. m %= 60; if(h > 23){ //2..
[백준] 2884 - 알람 시계 import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int h, m; do{ h = sc.nextInt(); m = sc.nextInt(); if(m -1 || h -1 || m < 60); sc.close(); } } 태블릿에 손코딩 해보면..
[백준] 14681 - 사분면 고르기 제 1사분면은 x(+), y(+) / 제 2사분면은x(-), y(+) / 제 3사분면은 x(-), y(-) / 제 4사분면은 x(+), y(-) 이다. 제 2사분면(-, +) 제 1사분면(+, +) 제 3사분면(-, -) 제 4사분면(+, -) import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int x, y; x = sc.nextInt(); y = sc.nextInt(); if(x > 0 && y > 0){ System.out.println(1); }else if(x 0){ System.out.println(2); }else i..
[백준] 2753 - 윤년 1. 연도가 4의 배수이면서 100의 배수가 아닐 때, 2. 400의 배수일 때 를 잘 확인하면서 해야한다. import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int year; year = sc.nextInt(); sc.close(); if((year%4 == 0 && year%100 != 0) || (year%400 == 0)){ System.out.println(1); } else{ System.out.println(0); } } }

반응형