-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1755.cpp
75 lines (68 loc) · 1.94 KB
/
1755.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
74
75
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define endl "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll i, n;
string s;
cin >> s;
n = s.size();
ll count_arr[26];
memset(count_arr, 0, sizeof(count_arr));
for(i = 0; i < n; ++i)
{
count_arr[s[i] - 'A']++;
}
ll odd = 0;
for(i = 0; i < 26; ++i)
{
if(count_arr[i] % 2)
{
odd++;
}
}
//cout << odd << endl;
if(odd > 1)
{
cout << "NO SOLUTION" << endl;
}
else
{
string result;
for(i = 0; i < 26; ++i)
{
if(count_arr[i] % 2 == 0)
{
for(ll j = 0; j < count_arr[i] / 2; ++j)
{
result.push_back(i + 'A');
}
}
}
for(i = 0; i < 26; ++i)
{
if(count_arr[i] % 2)
{
for(ll j = 0; j < count_arr[i]; ++j)
{
result.push_back(i + 'A');
}
}
}
for(i = 25; i >= 0; --i)
{
if(count_arr[i] % 2 == 0)
{
for(ll j = 0; j < count_arr[i] / 2; ++j)
{
result.push_back(i + 'A');
}
}
}
cout << result << endl;
}
return 0;
}