728x90
반응형

java 38

[Baekjoon/JAVA] 백준 10871번 X보다 작은 수

x보다 작은 수만 골라서 출력해야 하는 문제입니다. import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); StringTokenizer st; st = new StringTokenizer(br.readLine()," "); int n = Integer.parseInt(st.nextToken()); int x = Integer...

[Baekjoon/JAVA] 백준 25314번 코딩은 체육과목 입니다

4의 배수만큼 long을 붙이면 되는 문제입니다. 공백도 함께 붙여야 합니다. 입력값은 반드시 4의 배수입니다. import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int n = Integer.parseInt(br.readLine()); int a = n/4; for(int i=0; i

Algorithm/문자열 2023.06.27

[Baekjoon/JAVA] 백준 15552번 빠른 A + B

이 문제는 단순히 A + B를 출력하면 되는 문제이지만, 시간 제한이 걸려 있어 Scanner를 사용하면 문제를 풀 수 없습니다. 따라서 비교적 처리속도가 빠른 BufferedReader, BufferedWriter를 이용해야 합니다. import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[]args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter..

[Baekjoon/JAVA] 백준 2439번 별 찍기 - 2

입력받은 갯수만큼 별을 오른쪽으로 정렬하는 문제입니다. 공백+별 형식이 되겠군요. import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int count = 1; for(int i=n; i>0; i--) { String str = new String(new char[i-1]).replace("\0"," "); String star = new String(new char[count]).replace("\0","*"); System.out.println(str+star); count += 1; } } } 저..

Algorithm/문자열 2023.06.26

[Baekjoon/JAVA] 백준 25304번 영수증

1. 총액 2. 물건 종류의 수 3~. 물건 종류별 가격과 갯수 이렇게 입력받게 됩니다. 물건 종류별 가격과 갯수를 계산하여, 처음에 입력받은 총액과 일치하는지 검사하는 문제입니다. import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(); int n = scan.nextInt(); int result = 0; for(int i=0; i

[Baekjoon/JAVA] 백준 2884번 알람 시계

즉, 입력받은 시간의 45분 전 시간을 출력하면 되는 문제입니다. import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); if(b >= 45){ System.out.println(a+" "+(b-45)); } else if(a == 0){ System.out.println("23 "+(b+15)); } else{ System.out.println((a-1)+" "+(b+15)); } } } a를 시, b를 분 이라고 합시다. 1번 조건 : b가 45 이상일 경우 ..

728x90
반응형