字符串的展开
2021秋季算法入门班
1001
#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-x))
void solve()
{
int p1, p2, p3;
std::cin >> p1 >> p2 >> p3;
std::string s;
std::cin >> s;
const int n = s.size();
std::string ans;
for (int i = 0; i < n; i++)
{
if (s[i] == '-')
{
if (i == 0 || i == n - 1)
{
ans.push_back(s[i]);
}
else
{
char a = s[i - 1];
char b = s[i + 1];
if (isalpha(a) && isalpha(b))
{
if (a < b)
{
std::string t;
for (int i = (a - 'a') + 1; i < (b - 'a'); i++)
{
for (int j = 0; j < p2; j++)
{
if (p1 == 3) {
t.push_back('*');
}
else if (p1 == 1)
{
t.push_back(char(i + 'a'));
}
else
{
t.push_back(char(i + 'A'));
}
}
}
if (p3 == 2)
{
std::reverse(t.begin(), t.end());
}
ans += t;
}
else
{
ans.push_back(s[i]);
}
}
else if (isdigit(a) && isdigit(b))
{
if (a < b)
{
std::string t;
for (int i = (a - '0' + 1); i < (b - '0'); i++)
{
for (int j = 0; j < p2; j++)
{
if (p1 == 3) {
t.push_back('*');
}
else
{
t.push_back(char(i + '0'));
}
}
}
if (p3 == 2)
{
std::reverse(t.begin(), t.end());
}
ans += t;
}
else
{
ans.push_back(s[i]);
}
}
else
{
ans.push_back(s[i]);
}
}
}
else
{
ans.push_back(s[i]);
}
}
std::cout << ans << '\n';
}
int main()
{
int T = 1;
while (T--) solve();
return 0;
}