68分,问题在哪呢
查看原帖
68分,问题在哪呢
169144
cxzy5375楼主2023/1/7 21:39
#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;
}
2023/1/7 21:39
加载中...