【洛谷】P1098 字符串的展开
问题:
1、 - 的左右两边需要全是字母或全是数字
2、数字不需要大写转小写
3、数字字符只有0到9
题解:
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int p1,k,p3;
string s;
cin>>p1>>k>>p3;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='-'&&((s[i-1]>=97&&s[i-1]<=122&&s[i+1]>=97&&s[i+1]<=122)||(s[i-1]>=48&&s[i-1]<=57&&s[i+1]>=48&&s[i+1]<=57)))
{
if(s[i+1]-s[i-1]==1) //左右连续
{
}
else if(s[i+1]-s[i-1]<=0) //左小于右
{
cout<<'-';
}
else
{
if(p3==1)
{
if(p1==1) //填小写
{
for(int j=int(s[i-1])+1;j<int(s[i+1]);j++)
{
int s=k;
while(s--)
cout<<char(j);
}
}
else if(p1==2)
{
if(s[i-1]>=97&&s[i-1]<=122&&s[i+1]>=97&&s[i+1]<=122)
{
for(int j=int(s[i-1])+1;j<int(s[i+1]);j++)
{
int s=k;
while(s--)
cout<<char(j-32);
}
}
else
{
for(int j=int(s[i-1])+1;j<int(s[i+1]);j++)
{
int s=k;
while(s--)
cout<<char(j);
}
}
}
else if(p1==3)
{
for(int j=int(s[i-1])+1;j<int(s[i+1]);j++)
{
int s=k;
while(s--)
cout<<'*';
}
}
}
else if(p3==2)
{
if(p1==1) //填小写
{
for(int j=int(s[i+1])-1;j>int(s[i-1]);j--)
{
int s=k;
while(s--)
cout<<char(j);
}
}
else if(p1==2)
{
if(s[i-1]>=97&&s[i-1]<=122&&s[i+1]>=97&&s[i+1]<=122)
{
for(int j=int(s[i+1])-1;j>int(s[i-1]);j--)
{
int s=k;
while(s--)
cout<<char(j-32);
}
}
else
{
for(int j=int(s[i+1])-1;j>int(s[i-1]);j--)
{
int s=k;
while(s--)
cout<<char(j);
}
}
}
else if(p1==3)
{
for(int j=int(s[i+1])-1;j>int(s[i-1]);j--)
{
int s=k;
while(s--)
cout<<'*';
}
}
}
}
}
// else if(s[i]=='-'&&(s[i-1]>=97&&s[i-1]<=122&&s[i+1]>=97&&s[i+1]<=122))
else
cout<<s[i];
}
return 0;
}