solved.ac
알고리즘 문제해결 학습의 이정표 🚩 Baekjoon Online Judge 난이도 및 티어 정보 제공
solved.ac
Class 1 문제부터 차례대로 풀어보기~
🌼 백준 1000
A + B
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();
if(a <= 0 || b <= 0)
return ;
System.out.println(a + b);
}
}
🌼 백준 1001
A - B
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();
if(a <= 0 || b <= 0)
return ;
System.out.println(a - b);
}
}
🌼 백준 1008
A / B
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();
if(a <= 0 || b <= 0)
return ;
System.out.println((double)a / b);
}
}
🌼 백준 10171
고양이 출력하기
public class Main {
public static void main(String[] args) {
System.out.println("\\ /\\");
System.out.println(" ) ( ')");
System.out.println("( / )");
System.out.println(" \\(__)|");
}
}
🌼 백준 10172
강아지 출력하기
public class Main {
public static void main (String[] args) {
System.out.println("|\\_/|");
System.out.println("|q p| /}");
System.out.println("( 0 )\"\"\"\\");
System.out.println("|\"^\"` |");
System.out.println("||_/=\\\\__|");
}
}
🌼 백준 10809
📝 아스키코드
알파벳 a 는 숫자로 저장된다.
이 규칙에 유의! 'a' + 1 은 'b' 로 출력된다.
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
sc.close();
int[] alphabet = new int[26];
Arrays.fill(alphabet, -1); // -1로 초기화
// System.out.println(c - 'a');
for(int i = 0; i < str.length(); i++)
{
if(alphabet[str.charAt(i) - 'a'] == -1) // 처음 나오는 문자일 경우
alphabet[str.charAt(i) - 'a'] = i;
}
for(int j = 0; j < 26; j++)
{
System.out.print(alphabet[j] + " ");
}
}
}
🌼 백준 10818
📝 Arrays.sort(int_array)
정수형 배열 int_array 를 정렬해주면 오름차순 정렬된다.
이 방법을 사용하려면 index 값이 의미가 없을 때만 사용 가능!
max 나 min 값의 index값이 중요하다면 변수를 선언해 for문을 돌려야 한다.
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String[] str = sc.nextLine().split(" ");
sc.close();
int[] num = new int[n];
int max;
int min;
for(int i = 0; i < n; i++)
{
num[i] = Integer.parseInt(str[i]);
}
Arrays.sort(num);
System.out.print(num[0] + " " + num[num.length - 1]);
}
}
🌼 백준 10869
사칙연산
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);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a % b);
}
}
🌼 백준 10871
x 보다 작은 수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
sc.nextLine();
for(int i = 0; i < n; i++)
{
int a = sc.nextInt();
if(a < x)
System.out.print(a + " ");
}
}
}
🌼 백준 10950
A + B - 3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
// System.out.println(String.valueOf(n));
for(int i = 0; i < n; i++)
{
String[] ab = br.readLine().split(" ");
int a = Integer.parseInt(ab[0]);
int b = Integer.parseInt(ab[1]);
System.out.println(String.valueOf(a+b));
}
br.close();
}
}
'java 개발일지' 카테고리의 다른 글
백준 Class 1 java #2438 ~ #2742 (1) | 2022.09.26 |
---|---|
백준 Class 1 java #10951 ~ #1546 (0) | 2022.09.26 |
재귀함수 코드업 1091, 1092 / 백준 10872, 10870 (2) | 2022.09.20 |
코드업 기초100제, #1092 ~ #1099 (0) | 2022.09.17 |
코드업 기초100제, #1083 ~ #1091 (1) | 2022.09.15 |
댓글