前往
大廳
主題

[OJ練習] 673、10696 字串真的不簡單欸 ouo 腦袋要很清楚

テリ君(福佬模式) | 2022-12-20 12:49:37 | 巴幣 4 | 人氣 170

673(2/5)


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int t;
    scanf("%d", &t);
    
    for(int i = 0; i < t; i++){
        char line[129] = {0};
        scanf("%s", line);
        
        int stack[129];
        int top = 0;
        int valid = 1;
        
        for(int j = 0; j < strlen(line); j++){
            char c = line[j];
            if(c == '(' || c == '[') stack[top++] = c;
            else if(c == ')' || c == ']'){
                if((c == ')' && stack[top - 1] != '(') || (c == ']' && stack[top - 1] != '[')) valid = 0;
                else top--;
            }
        }
        if(valid && top == 0) printf("Yes\n");
        else printf("No\n");
    }
    
    return 0;
}

10696(1/5)


#include <stdio.h>

int f91(int n){
    int result;
    if(n <= 100){
        result = f91(f91(n + 11));
    }
    else if(n >= 101){
        result = n - 10;
    }
    
    return result;
}


int main(){
    int N = 0;
    while(scanf("%d", &N)){
        if(N == 0) break;
        printf("f91(%d) = %d\n", N, f91(N));
    }
    
    return 0;
}

673就是要搞清楚括弧們有沒有確認過有配對到,有的話就要跳到下一個確認,不然都會是一個配好幾個= = 還有chatGPT真的好棒喔,雖然他一直出錯但我還是把他糾正到對了(X

10696就是很簡單的function應用。

創作回應

更多創作