4시간은 붙들고 있었는데 도저히 안 풀린다. 하..
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
string solution(vector<int> numbers) {
string answer = "";
priority_queue<pair<int, int>> q;
for(int i;i<numbers.size();i++){
string f = to_string(numbers[i]);
for(int j=to_string(numbers[i]).size();j<3;j++){
f += f[0];
}
q.push(make_pair(stoi(f), numbers[i]));
}
while(!q.empty()){
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> sec;
priority_queue<pair<int, int>> sec_rev;
int f = q.top().first;
bool rev = false;
if(to_string(q.top().second)[0] > to_string(q.top().second)[1])
rev = true;
while(q.top().first == f && !q.empty()){
string s = to_string(q.top().second);
if(rev)
sec_rev.push(make_pair(s.size(),q.top().second));
else
sec.push(make_pair(s.size(),q.top().second));
q.pop();
}
if(rev){
while(!sec_rev.empty()){
if(answer == "0")
answer = "";
answer += to_string(sec_rev.top().second);
sec_rev.pop();
}
}else{
while(!sec.empty()){
if(answer == "0")
answer = "";
answer += to_string(sec.top().second);
sec.pop();
}
}
}
return answer;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(const string &a, const string &b) {
return a + b > b + a ? true : false;
}
string solution(vector<int> numbers) {
string answer = "";
vector<string> strArr;
for (int i = 0; i < numbers.size(); i++) {
strArr.push_back(to_string(numbers.at(i)));
}
sort(strArr.begin(),strArr.end(),cmp);
for (string str : strArr) {
answer += str;
}
if (answer[0] == '0')
return "0";
return answer;
}