[java] 백준 단계별로 풀어보기 1단계 (2)알고리즘/백준2021. 6. 17. 16:53
Table of Contents
6단계 1001번 A - B
import java.util.Scanner;
class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.print(a-b);
}
}
7단계 10998번 A X B
import java.util.Scanner;
class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a*b);
}
}
8단계 1008번 A / B
import java.util.Scanner;
class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println((double)a/b);
}
}
9단계 10869번 사칙연산
import java.util.Scanner;
class Main{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
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);
}
}
10단계 10430번 나머지
import java.util.Scanner;
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);
}
}
11단계 2588번 곱셈
import java.util.Scanner;
import java.lang.Math;
class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = 0;
int[] arr = new int[3];
int[] arr2 = new int[3];
int[] tot = new int[3];
for(int i=2; i>-1; i--){
arr[i] = b/(int)Math.pow(10,i);
b-=arr[i]*(int)Math.pow(10,i);
}
arr2[0] = arr[2];
arr2[1] = arr[1];
arr2[2] = arr[0];
for(int j=2; j>-1; j--)
tot[j] = a*arr2[j];
for(int i=2; i>-1; i--)
System.out.println(tot[i]);
arr2[0] = tot[2];
arr2[1] = tot[1];
arr2[2] = tot[0];
for(int i=2; i>-1; i--) {
c += arr2[i] * (int) Math.pow(10, i);
}
System.out.println(c);
}
}
2588번 헬파티입니다...
'알고리즘 > 백준' 카테고리의 다른 글
[java] 백준 단계별로 풀어보기 3단계 (3) (0) | 2021.06.24 |
---|---|
[java] 백준 단계별로 풀어보기 3단계 (2) (0) | 2021.06.23 |
[java] 백준 단계별로 풀어보기 3단계 (1) (0) | 2021.06.19 |
[java] 백준 단계별로 풀어보기 2단계 (0) | 2021.06.17 |
[java] 백준 단계별로 풀어보기 1단계 (1) (0) | 2021.06.17 |
@펄찌 :: Pearl's Story
펄의 일상이 궁금한 사람 요기~
즐거운 하루 되셨으면 좋겠습니다😊