【洛谷】P1098 字符串的展开 2020-11-05

【洛谷】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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值