[백준 알고리즘]/[자바 Java]

백준 2675 2739 10818 10869 10950 | java 자바

말하는펭귄 2024. 1. 9. 16:11
728x90
반응형

이번 포스팅은 백준 2675, 2739, 10818, 10869, 10950번 자바 java 정답 코드입니다.

아래 url를 클릭하시면 백준 사이트에서 문제를 볼 수 있습니다.

https://www.acmicpc.net/problem/2675

 

2675번: 문자열 반복

문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다

www.acmicpc.net

https://www.acmicpc.net/problem/2739

 

2739번: 구구단

N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다.

www.acmicpc.net

 

https://www.acmicpc.net/problem/10818

 

10818번: 최소, 최대

첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.

www.acmicpc.net

https://www.acmicpc.net/problem/10869

 

10869번: 사칙연산

두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오. 

www.acmicpc.net

https://www.acmicpc.net/problem/10950

 

10950번: A+B - 3

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

전체 코드

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//백준 2675 문자열 반복
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s="", p="";
        int t=0, r=0;
 
        t=sc.nextInt();
        for(int i=0; i<t; i++, p=""){
            r=sc.nextInt();
            s=sc.next();
 
            for(int j=0; j<s.length(); j++){
                for(int k=0; k<r;k++){
                    p+=s.charAt(j);
                }
            }
            
            System.out.println(p);
        }
 
        sc.close();
    }
}
 
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//백준 2739 구구단
import java.util.Scanner;
 
public class Boj2739 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=0, mul=0;
 
        n=sc.nextInt();
 
        for(int i=1; i<=9; i++){
            mul= n*i;
            System.out.println(n+" * "+i+" = "+n*i);
        }
 
        sc.close();
    }
}
 
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//백준 10818 최소, 최대
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=0, input=0, max= -1000001, min= 1000001;
 
        n=sc.nextInt();
        for(int i=0;i<n;i++){
            input=sc.nextInt();
            if(input>max){
                max=input;
            }
            if(input<min){
                min=input;
            }
        }
 
        System.out.print(min+" "+max);
 
        sc.close();
    }
}
 
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//백준 10869 사칙연산
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=0, b=0, sum=0, diff=0, mul=0, div=0, rem=0;
 
        a=sc.nextInt();
        b=sc.nextInt();
        sum=a+b;
        diff=a-b;
        mul=a*b;
        div=a/b;
        rem=a%b;
 
        System.out.println(sum);
        System.out.println(diff);
        System.out.println(mul);
        System.out.println(div);
        System.out.println(rem);
 
        sc.close();
    }
}
 
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//백준 10950 A+B - 3
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=0, a=0, b=0, sum=0;
 
        t=sc.nextInt();
        for(int i=0; i<t; i++){
            a=sc.nextInt();
            b=sc.nextInt();
            sum=a+b;
            System.out.println(sum);
        }
 
        sc.close();
    }
}
 
cs

 

 

 

728x90
반응형