60分求调,6AC4WA
查看原帖
60分求调,6AC4WA
1344178
Xrupz1234楼主2025/6/14 11:14
#include<bits/stdc++.h>
using namespace std;
string f;
void dg(string g){
	int i=0,k=0,l=-1,r;
	for(int j=0;j<g.size();j++){
		if(g[j]=='['){
			l = j;
			break;
		}
	}
	for(int j=g.size()-1;j>=0;j--){
		if(g[j]==']'){
			r = j;
			break;
		}
	}
	if(l==-1){
		cout<<g;
		return ;
	}else{
		int t = 0; 
		if(g[l+2]>='0'&&g[l+2]<='9'){//判断是几位数字 
			t=g[l+2]-'0'+10*(g[l+1]-'0');
			i=l+2;
		}else{
			t=g[l+1]-'0';
			i=l+1;
		}
		string b="";
		for(int j=i+1;j<=r-1;j++){//数字后的位数判断 
			b+=g[j];
		}
		for(int j=0;j<l;j++){//打印'['前面的字符 
			cout<<g[j];
		}
		for(int j=0;j<t;j++){//递归 
			dg(b);
		}
		for(int j=r+1;j<g.size();j++){//打印从数字到']'的字符
			cout<<g[j];
		}
	}
	
}
int main(){
	cin>>f;
	dg(f);
	return 0;
}
2025/6/14 11:14
加载中...