Notice
Recent Posts
Recent Comments
Link
«   2024/12   »
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 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-2935번/Java] 소음 본문

Algorithm

[백준-2935번/Java] 소음

1984 2022. 11. 9. 20:49

* Math.max

* Math.min

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String A = sc.nextLine();
		String operator = sc.nextLine();
		String B = sc.nextLine();

		String answer = "1";

		int A_size = A.length();
		int B_size = B.length();

		if (operator.equals("*")) {
			for (int i = 0; i < (A_size - 1) + (B_size - 1); i++) {
				answer += "0";
			}
			System.out.println(answer);
		} else if (operator.equals("+")) {
			if (A_size == B_size) {
				answer = "2";
				for (int i = 1; i < A_size; i++) {
					answer += "0";
				}
			} else {
				for (int i = 1; i < Math.max(A_size, B_size); i++) {
					if (i == Math.max(A_size, B_size) - Math.min(A_size, B_size)) {
						answer += "1";
					} else {
						answer += "0";
					}
				}
			}

			System.out.println(answer);
		}

	}

}
728x90

'Algorithm' 카테고리의 다른 글

[백준-1789번/Java] 수들의 합  (0) 2022.11.09
[백준-11653번/Java] 소인수분해  (0) 2022.11.09
[백준-2675번/Java] 문자열 반복  (0) 2022.11.09
[백준-5355번/Java] 화성수학  (0) 2022.11.09
[백준-2914번/Java] 저작권  (0) 2022.11.09
Comments