救 70
查看原帖
救 70
471033
fanersaiwenxue楼主2021/7/23 16:52

70 真的看不懂题

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[105];
int main()
{
	int i,j;
	char s[10001];
	cin>>s;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]==')')
		{
			for(j=i-1;j>=0;j--)
			{
				if(s[j]=='(' and a[j]==0)
				{
					a[i]=a[j]=1;
					break;
				}
				else if(s[j]==']' and a[j]==0)
				break;
			}
		}
		else if(s[i]==']')
		{
			for(j=i-1;j>=0;j--)
			{
				if(s[j]=='[' and a[j]==0)
				{
					a[i]=a[j]=1;
					break;
				}
				else if(s[j]=='(' and a[j]==0)
				break;
			}
		}
	}
	for(i=0;i<strlen(s);i++)
	{
		if(a[i]==0)
		{
			if(s[i]=='(' or s[i]==')')
			{
				cout<<"()";
			}
			else cout<<"[]";
		}
		else cout<<s[i];
	}
	return 0;
}
2021/7/23 16:52
加载中...