• 30을 만족하기 위해서는 10으로 한 번 나누어져야 하고, 각 자리수의 합이 3의 배수여야 한다.
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
32
33
34
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

bool compare(char a, char b) {
	return a > b;
}

int main() {
	string str;
	cin >> str;

	long long sum = 0;
	bool isZero = false;
	for (int i = 0; i < str.size(); i++) {
		int num = str[i] - '0';
		sum += num;
		if (num == 0)
			isZero = true;
	}
	long long res = -1;
	if (sum % 3 == 0 && isZero) {
		sort(str.begin(), str.end(), compare);
		cout << str << endl;
	}
	else
		cout << "-1" << endl;
	return 0;
}