题解 | 字符串展开
字符串展开
https://www.nowcoder.com/practice/7fea6add1afa4d91ad71b3a3f4032880
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int p1,p2,p3;
cin>>p1>>p2>>p3;
string s;
cin>>s;
vector<int>res;
for(int i = 0;i<s.size();++i)
{
if(s[i] == '-')
{
if(i>0&&i<s.size()-1)
{
int sta = s[i-1];
int end = s[i+1];
if((sta>=48&&sta<=57&&end>=48&&end<=57)||(sta>=97&&sta<=122&&end>=97&&end<=122)){
if((end - sta)>1)
{
if(p1 == 3)
{
string s1 = string((end-sta-1)*p2,'*');
cout<<s1;
}else if(p1 == 1)
{
if(p3 == 1)
{
string s1 = "";
for(int j = sta+1;j<end;++j)
{
char a = char(j);
s1+=string(p2,a);
}
cout<<s1;
}else {
string s1 = "";
for(int j = end-1;j>sta;--j)
{
char a = char(j);
s1+=string(p2,a);
}
cout<<s1;
}
}else if(p1 == 2)
{
if(p3 == 1)
{
string s1 = "";
for(int j = sta+1;j<end;++j)
{
char a;
if(j>=97&&j<=122)
a = char(j-32);
else
a = char(j);
s1+=string(p2,a);
}
cout<<s1;
}else {
string s1 = "";
for(int j = end-1;j>sta;--j)
{
char a;
if(j>=97&&j<=122)
a = char(j-32);
else
a = char(j);
s1+=string(p2,a);
}
cout<<s1;
}
}
}else if((end-sta)<=0)
{
cout<<'-';
}else {
continue;
}
}else {
cout<<'-';
}
}else {
cout<<'-';
}
}else {
cout<<s[i];
}
}
}

