https://www.acmicpc.net/problem/10610
#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX 100001
using namespace std;
bool cmp(char x, char y) { //내림차순 함수
return (x > y);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
char n[MAX];
cin >> n;
int IsContainsZero=false;
int sum = 0;
for (int i = 0; i < strlen(n); i++) { //각 숫자의 합을 구한다. 0이 있으면 표시한다.
sum +=n[i]-'0';
if (n[i] == '0') IsContainsZero=true;
}
if (IsContainsZero && (sum % 3) == 0) {
sort(n, n+strlen(n),cmp); //숫자를 내림차순 정렬한다.
cout << n << "\n";
}
else cout << "-1\n";
return 0;
}