본문 바로가기
백준 알고리즘/그리디 알고리즘

백준 10610번 C++

by paysmile 2019. 2. 18.

#include <iostream>

#include <algorithm>

#include <cstring>

using namespace std;


const int MAX = 100001;

char number[MAX];

int length;


bool cmp(char c1,  char c2) {

return c1 > c2;

}


int main(void) {

cin >> number;

length = strlen(number);


int flag = 0;

int sum = 0;


for (int i = 0; i < length; i++) {

sum = sum + (number[i] - '0');

if (number[i]== '0')

flag = 1;

}

if ((flag == 1) && (sum % 3 == 0)) {

sort(number, number + length, cmp);

cout << number;

}

else

cout << -1;

return 0;

}



'백준 알고리즘 > 그리디 알고리즘' 카테고리의 다른 글

로프 C++  (0) 2019.10.10
백준 1120번 C++  (0) 2019.08.28
백준 1931번 C++  (0) 2019.02.18
백준 11047번 C++  (0) 2019.02.18
백준 1764번 C++  (0) 2019.02.18