-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
73 lines (52 loc) · 1.21 KB
/
test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
#include <queue>
using namespace std;
// Definition for a binary tree node.
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
int maxdepth(TreeNode* root){
int c=0;
if(root==NULL) return;
int lh=maxdepth(root->left);
int rh=maxdepth(root->right);
c=max(lh,rh)+1;
return c;
}
int main(){
TreeNode* root = new TreeNode(1);
root->left = new TreeNode(2);
root->right = new TreeNode(3);
root->left->left = new TreeNode(4);
root->left->right = new TreeNode(5);
cout << "Maximum depth of the tree: " << maxdepth(root) << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void solve(string &s) {
vector<int> numbers;
for (char c : s) {
if (c != '+') {
numbers.push_back(c - '0');
}
}
sort(numbers.begin(), numbers.end());
s.clear();
for (size_t i = 0; i < numbers.size(); ++i) {
s += to_string(numbers[i]);
if (i < numbers.size() - 1) {
s += '+';
}
}
cout << s << endl;
}
int main() {
string s;
getline(cin, s);
solve(s);
return 0;
}