-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontest-102254.cpp
58 lines (49 loc) · 1016 Bytes
/
contest-102254.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 <iostream>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
int counts [10];
string first;
string second;
string temp;
cin >> first;
while (true)
{
memset(counts, 0, sizeof(counts));
temp.clear();
for (auto c : first)
{
++counts[c - '0'];
}
for (auto c : first)
{
int count = counts[c - '0'];
if (count == 1)
{
second += c;
counts[c - '0'] = 0;
}
else if (count > 1)
{
second += c;
temp += to_string(count);
counts[c - '0'] = 0;
}
}
second += temp;
sort(second.begin(), second.end());
if (second == first)
{
break;
}
else
{
first = move(second);
}
}
cout << second << endl;
return 0;
}