【模拟】字符串展开

D e s c r i p t i o n Description

在这里插入图片描述

T r a i n Train O f Of T h o u g h t Thought

直接模拟就好了,只要注意一点小问题就好了
这道题其实就是代码量有点大,细节比较多
注意点就好了

C o d e Code

#include<cstdio>
#include<string> 
#include<cstring>
#include<iostream>
using namespace std;
int cc,len,p1,p2,p3;
string s,s2;
bool b,c,bb;
void work(int tt)
{
	for (int i=tt; i<len; ++i)
	 {
	 	if (s[i]>='0' && s[i]<='9' && b) break; 
		 else if (s[i]>='a' && s[i]<='z'  && c) break; 
		  else if (s[i]=='-') break;
		   else s2+=s[i];
		++cc;
	 }//记录第二串字符串
	if (s2[0]==s[tt-2]+1) {cout<<s2; return;}
	 else if (s2[0]<=s[tt-2]) {printf("-"); cout<<s2; return;}//两种特殊情况
	if (p3==1)
	{
		if (p1==3)
		{
			for (int i=1; i<=s2[0]-s[tt-2]-1; ++i)
			{
				for (int j=1; j<=p2; ++j)
				 	printf("*");
			}
		}
		 else if (p1==2)
		 {
		 	if (c) {
		 		for (int i=1; i<=s2[0]-s[tt-2]-1; ++i)
				{
					char c=s[tt-2]+i;
					for (int j=1; j<=p2; ++j)
				 		cout<<c;
				}
		 	}
		 	 else {
		 	 	for (int i=1; i<=s2[0]-s[tt-2]-1; ++i)
				{
					char c=s[tt-2]+i-32;
					for (int j=1; j<=p2; ++j)
				 		cout<<c;
				}
		 	 }
		 }
		  else {
		  	for (int i=1; i<=s2[0]-s[tt-2]-1; ++i)
		  	 {
		  	 	char c=s[tt-2]+i;
		  	 	for (int j=1; j<=p2; ++j)
		  	 		cout<<c;
		  	 }
		  }
	}
	 else {
	 	if (p1==3)
		{
			for (int i=1; i<=s2[0]-s[tt-2]-1; ++i)
			{
				for (int j=1; j<=p2; ++j)
				 	printf("*");
			}
		}
		 else if (p1==2)
		 {
		 	if (c) {
		 		for (int i=s2[0]-s[tt-2]-1; i>=1; --i)
				{
					char c=s[tt-2]+i;
					for (int j=1; j<=p2; ++j)
				 		cout<<c;
				}
		 	}
		 	 else {
		 	 	for (int i=s2[0]-s[tt-2]-1; i>=1; --i)
				{
					char c=s[tt-2]+i-32;
					for (int j=1; j<=p2; ++j)
				 		cout<<c;
				}
		 	 }
		 }
		  else {
		  	for (int i=s2[0]-s[tt-2]-1; i>=1; --i)
		  	 {
		  	 	char c=s[tt-2]+i;
		  	 	for (int j=1; j<=p2; ++j)
		  	 		cout<<c;
		  	 }
		  }
	 }
	cout<<s2;//按题意模拟(以上都是)
}
int main()
{
	scanf("%d%d%d",&p1,&p2,&p3);
	cin>>s;
	len=s.size();
	for (int i=0; i<len; ++i)
	{
		char ccc;
		while (!bb && s[i]=='-') printf("-"),++i;//特判
		if (s[i]!='-') printf("%c",s[i]),ccc=s[i],bb=true;
		 else {
		 	if (ccc>='a' && ccc<='z') b=true;
		 	 else c=true;//判断是数字还是字母
		 	if (s[i+1]=='-') {cout<<"--"; ++i; continue;}//特判
		 	 else work(i+1);
		 	b=c=false;
		 	i+=cc;
		 	cc=0;
		 	s2="";
		 }
	}	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/LTH060226/article/details/89025291
今日推荐