#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int p1,p2,p3;
bool q=0;//用于标记‘-’号两边字符不符合处理要求的情况
string str,ww;//str为读入的待处理字符串,ww记录每次处理(展开)的结果;
void init()
{
cin>>p1>>p2>>p3;
cin>>str;
}
void work_numb(int k1,int k2)//处理‘-’两边都是数字的情况
{
q=1;//每次开头让q为真,避免等下的特判退出后不能及时记录。
if(str[k1]>=str[k2]) { cout<<'-';return;}//特判前面字符大于等于后面字符
if(str[k2]-str[k1]==1) return;//特判前后两字符相邻
string ww="";//让记录展开结果字符串为空
for(int i=str[k1]+1;i<str[k2];i++)
for(int j=1;j<=p2;j++)
if(p1==3) ww+='*';
else ww+=char(i);
if(p3==2)
reverse(ww.begin(),ww.end());//如果p3==2就让字符串翻转(!!!一定要注意reverse拼写,检查20分钟发现单词拼错了Orz。。。!!!)
cout<<ww;
}
void work_word(int k1,int k2)//处理‘-’两边都是字母。大体同上
{
q=1;
if(str[k1]>=str[k2]) { cout<<'-';return;}
if(str[k2]-str[k1]==1) return;
string ww="";
for(int i=str[k1]+1;i<str[k2];i++)
for(int j=1;j<=p2;j++)
{
if(p1==1)
ww+=char(i);
if(p1==2)
ww+=char(i-32);
if(p1==3)
ww+='*';
}
if(p3==2)
reverse(ww.begin(),ww.end());
cout<<ww;
}
int main()
{
init();
if(str.find('-')==-1) {cout<<str<<endl; return 0;}
while(str.find('-')!=-1)
{
q=0;
int ption=str.find('-');
for(int i=0;i<ption;i++)
cout<<str[i];//先输出‘-’前面的字符
if(str[ption-1]>='0' && str[ption-1]<='9' && str[ption+1]>='0' && str[ption+1]<='9')
work_numb(ption-1,ption+1);//处理数字展开
if(str[ption-1]>='a' && str[ption-1]<='z' && str[ption+1]>='a' && str[ption+1]<='z')
work_word(ption-1,ption+1);//处理字母展开
if(!q)
cout<<'-';//如果没有被上面两个函数任何一个处理就将执行
str.erase(0,ption+1); //删除‘-’及前面所有字符
}
cout<<str<<endl;//输出最后一段字符
return 0;
}
OJ P1109 字符串展开
最新推荐文章于 2022-03-02 14:09:22 发布