-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[LV1] 숫자 짝궁.cpp
58 lines (49 loc) · 1.34 KB
/
[LV1] 숫자 짝궁.cpp
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
50
51
52
53
54
55
56
57
58
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
using namespace std;
string solution(string X, string Y) {
string answer = "";
vector<char> my_vec;
for(int i=0; i<10; ++i){
my_vec.push_back(i + '0');
}
// for(const auto& elem: my_vec){
// cout << elem << endl;
// }
// int char_count_num = count(X.begin(), X.end(), '1');
// cout << char_count_num << endl;
for(const auto& elem: my_vec){
int x_count = count(X.begin(), X.end(), elem);
int y_count = count(Y.begin(), Y.end(), elem);
// cout << x_count << " " << y_count << endl;
if(x_count !=0 and y_count !=0){
if(x_count > y_count){
for(int i=0; i<y_count; ++i){
answer += elem;
}
}else{
for(int i=0; i<x_count; ++i){
answer += elem;
}
}
}
}
int zero_cnt = count(answer.begin(), answer.end(), '0');
if(answer.empty()){
answer = "-1";
return answer;
}
else if(zero_cnt == answer.size()){
answer = "0";
return answer;
}
else{
sort(answer.begin(), answer.end(), greater<>());
}
return answer;
}