-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoAdjecnt.cpp
106 lines (86 loc) · 1.83 KB
/
NoAdjecnt.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <map>
#include <vector>
using namespace std;
string shabya_method(string input)
{
map<char, int> freq;
char str[input.length() + 2];
for (int i = 0; i < input.length(); i++)
{
freq[input[i]]++;
}
char maxv;
int maxf = 0;
for (auto i : freq)
{
/* code */
if (i.second > maxf)
{
maxf = i.second;
maxv = i.first;
}
// cout<<i.first<<" "<<i.second<<endl;
}
cout << "maxf" << maxf << "\t maxv " << maxv << endl;
int len = input.length() + 1;
if (maxf <= len / 2)
{
for (int i = 0; i < len - 1; i++)
{
if (i % 2 == 0)
{
str[i] = maxv;
}
else
{
str[i] = 'z';
}
}
}
freq.erase(maxv);
int index = 1;
for (auto i : freq)
{
short temp = i.second;
while (temp--)
{
str[index] = i.first;
index += 2;
}
}
string out="";
for (size_t i = 0; i < input.length(); i++)
{
out+=str[i];
}
return out;
}
vector<string> my_method(string input)
{
vector<string> out;
for (size_t i = 0; i < input.length(); i++)
{
string out_1="";out_1+=input[i];
for (size_t j = 0; j < input.length(); j++)
{
if (out_1[out_1.length()-1]!=input[j] and i!=j)
{
out_1+=input[j];
}
}
out.push_back(out_1);
}
return out;
}
int main()
{
string input = "acccbbb";
cout<<shabya_method(input)<<endl;
vector<string> in = my_method(input);
for (int i = 0; i < in.size(); i++)
{
std::cout<<in[i]<<"\n";
}
return 0;
}