[백준] P1427

동민·2021년 3월 11일
0
import java.util.Scanner;

public class P1427 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int arr[];

		int n = sc.nextInt();

		int d = 1;
		int count = 0;

		while (true) {

			if (n / d == 0) {
				break;
			}
			d *= 10;
			count++;

		}

		arr = new int[count];

		d = (int) Math.pow(10, count - 1);
		for (int i = 0; i < count; i++) {

			arr[i] = n / d;
			n -= arr[i] * d;
			d /= 10;

		}

		int temp = 0;
		for (int i = 0; i < arr.length - 1; i++) {

			for (int j = arr.length - 1; j > i; j--) {

				if (arr[j - 1] < arr[j]) {
					temp = arr[j - 1];
					arr[j - 1] = arr[j];
					arr[j] = temp;
				}

			}

		}

		d = (int) Math.pow(10, count - 1);

		int sum = 0;
		for (int i = 0; i < arr.length; i++) {
			sum += arr[i] * d;
			d /= 10;
		}
		System.out.println(sum);

		sc.close();

	}

}
profile
BE Developer

0개의 댓글