50分求调,注释已写!
查看原帖
50分求调,注释已写!
956316
77Glorious楼主2023/10/27 21:44
#include<bits/stdc++.h>
using namespace std;

int p1,p2,p3;//类型,数量,顺序 
string s;

bool judge(char a,char b){//a b是否为同类型 
	if(isdigit(a)&&isdigit(b)) return 1;
	else if(isalpha(a)&&isalpha(b)) return 1;
	return false;
}

void exp(char a,char b){
	if(p3==1){//顺序
		for(char i=a+1;i<b;i++){
			if(p1==1){//小写
			 for(int j=0;j<p2;j++){
			 	cout<<tolower(i);//输出一定数字的小写字母 
			 }
			}else if(p1==2) {//大写
			 for(int j=0;j<p2;j++)
			 	cout<<toupper(i);
			}
			else if(p1==3){//星号 
			for(int j=0;j<p2;j++)
				cout<<'*';
			} 
		} 
	}//
	if(p3==2){//逆序
		for(char i=b-1;i>a;i--){
			if(p1==1){//小写
			 for(int j=0;j<p2;j++){
			 	cout<<tolower(i);//输出一定数字的小写字母 
			 }
			}else if(p1==2) {//大写
			 for(int j=0;j<p2;j++)
			 	cout<<toupper(i);
			}
			else if(p1==3){//星号 
			for(int j=0;j<p2;j++)
				cout<<'*';
			} 
		} 
	}//
}

//同类型-同类型,才可转换
//s[i]='-',若s[i+1]==s[i-1]+1,即相邻顺序,就去掉-
//s[i-1]<=s[i+1]就保留-
//else 保留- 
int main(){
	//p1 1小写,2大写,3*
	//p2个
	//p3 1顺序 2逆序
	cin>>p1>>p2>>p3>>s;
	for(int i=0;i<s.length();i++){
		
		if(s[i]=='-'){//开始展开 
			if(s[i-1]+1==s[i+1]) continue;//相邻顺序
			if(s[i-1]>=s[i+1]) {
				cout<<s[i]; continue;//右边比左边大,保留'-' 
			}
			else if(judge(s[i-1],s[i+1])){//如果都是同类型
			 	exp(s[i-1],s[i+1]);//展开字符串	
				continue;		  
			}
			
		}
		cout<<s[i];//非'-'直接输出 
	}
	
	
	
	
	return 0;
}
2023/10/27 21:44
加载中...