为啥卡在63分呢,求助,谢谢

P1241 括号序列

风人 @ 2020-06-06 22:13:34

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char a[101],s,b[101];

int main(){
    memset(b,0,sizeof(b));
    for (int i = 1;i > 0;i ++){
        s = getchar();
        if (s == '['){
            a[i] = '[';b[i] = ']';
        }
        else if (s == '('){
            a[i] = '(';b[i] = ')';
        }
        else if (s == ']'){
            a[i] = ']';
            for (int k = i; i;k --){
                if (b[k] == ']'){
                    b[k] = 0;
                    break;
                }
                if (k == 1){
                    a[i] ='[';
                    b[i] = 'z';
                    break;
                }
            }
        }
        else if (s == ')'){
            a[i] = ')';
            for (int k = i; i;k--){
                if (b[k] == ')'){
                    b[k] = 0;
                    break;
                }
                if (k == 1){
                    a[i] ='(';
                    b[i] = 'x';
                    break;
                }

            }
        }
        else break;
    }
    for (int i = 1;a[i];i ++){
        cout << a[i];
        if (b[i]){
            if ( b[i] == 'z') cout << ']';
            else if (b[i] == 'x') cout << ')';
            else cout << b[i];
        }    
    }

        return 0;
}

谢谢


|