cxzy5375 @ 2023-01-07 21:39:36
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
typedef long long LL;
struct ss
{
int vltd;
char s;
} st[500];
int main()
{
int cnt = 0;
for (int i = 1; i <= 400; i++)
st[i].vltd = 0;
while (~scanf("%c", &st[cnt].s) && st[cnt].s != '\n')
{
if (st[cnt].s == ')')
for (int j = cnt - 1; j >= 0; j--)
if (st[j].vltd == 0)
{
if (st[j].s == '(')
{
st[j].vltd = 1;
st[cnt].vltd = 1;
}
break;
}
if (st[cnt].s == ']')
for (int j = cnt-1; j >= 0; j--)
if (st[j].vltd == 0)
{
if (st[j].s == '[')
{
st[j].vltd = 1;
st[cnt].vltd = 1;
}
break;
}
cnt++;
}
st[cnt].s = '\0';
for (int j = 0; j < cnt; j++)
if (st[j].vltd == 1)
printf("%c", st[j].s);
else
{
switch (st[j].s)
{
case '(':
printf("()");
break;
case ')':
printf("()");
break;
case '[':
printf("[]");
break;
case ']':
printf("[]");
break;
}
}
return 0;
}
by C_wake @ 2023-05-17 22:51:29
我之前也是68分,你可以试一下样例([),输出应该是([])。
by C_wake @ 2023-05-17 22:52:06
可能是对题目的细节没理解到位
by C_wake @ 2023-05-17 22:54:38
详情看zhangzhihao2发的关于题意的细节这个帖子的讨论