티스토리 뷰

백준

백준 소스코드 [C++] 10610 30

Hani_Levenshtein 2020. 9. 9. 15:24

www.acmicpc.net/problem/10610

 

10610번: 30

어느 날, 미르코는 우연히 길거리에서 양수 N을 보았다. 미르코는 30이란 수를 존경하기 때문에, 그는 길거리에서 찾은 수에 포함된 숫자들을 섞어 30의 배수가 되는 가장 큰 수를 만들고 싶어한��

www.acmicpc.net

백준 소스코드 [C++] 10610 30

#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int sum = 0;
	vector <char> v;
	bool xx= false;
	string s;
	cin >> s;
	for (int j = 0;j < s.length();j++) {
		if (s[j] == '0') xx = true;
		v.push_back(s[j]);
		sum += s[j] - '0';
	}
	if (xx == true && sum%3==0) {
		sort(v.begin(),v.end(),greater<char>());
		for (int j = 0;j < (int)v.size();j++) cout << v[j];
	}
	else cout << "-1";
	return 0;
}
댓글