-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30.cpp
More file actions
49 lines (43 loc) · 636 Bytes
/
Copy path30.cpp
File metadata and controls
49 lines (43 loc) · 636 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Baekjoon 10610
// Greedy Algorithm
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string N;
int save;
bool zero;
bool three;
bool temp(char a, char b) {
if (a > b)
return true;
else
return false;
}
int main() {
cin >> N;
sort(N.begin(), N.end(), temp);
for (size_t i{ 0 }; i < N.length(); i++) {
if (N[i] == '0') {
if (i == 0) {
cout << "-1";
return 0;
}
zero = true;
break;
}
else {
save += (N[i] - '0');
save %= 3;
}
}
if (save == 0)
three = true;
if (zero == false || three == false) {
cout << "-1";
return 0;
}
else {
cout << N;
}
}