切換
舊版
前往
大廳
主題

[OJ練習] 12577、10050 重新開始更新!! 我是鬼吧(欸?

テリ君(福佬模式) | 2023-02-20 16:19:42 | 巴幣 4 | 人氣 214

GitHub
12577(1/5)
感覺有點偷吃步
請問這個是阿拉花瓜的概念ㄇ?

#include <stdio.h>

int main(){
    char c;
    int n = 0;
    while(scanf("%c", &c) != EOF){
        if(c == '*') break;
        else if(c == 'H'){
            printf("Case %d: Hajj-e-Akbar\n", n + 1);
            n++;
            continue;
        }
        else if(c == 'U'){
            printf("Case %d: Hajj-e-Asghar\n", n + 1);
            n++;
            continue;
        }
    }
    
    return 0;
}

10050(2/5)
有偷看一下題意解釋
怕理解錯
但我是鬼吧
一個月沒碰腦袋剛開機而已
code和註解打完一次就過
舒服

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

int main(){
    int T, days, P, *h, N = 0;
    // T for testcases, days for days, P for parties, *h for hartals, N for result
    bool *D;
    scanf("%d", &T);
    for(int i = 0; i < T; i++){
        scanf("%d", &days);
        scanf("%d", &P);
        // get Days and party hartal routines
        
        D = (bool*)malloc(sizeof(bool) * days);
        h = (int*)malloc(sizeof(int) * P);
        
        // mallocs days array and hartal int
        
        for(int j = 0; j < days; j++){
            *(D + j) = false;
        }
        
        // set days array to all false(no hartal)
        
        for(int j = 0; j < P; j++){
            scanf("%d", h + j);
            for(int k = 1; k <= days; k++){
                if(k % *(h + j) == 0) *(D + k) = true;
            }
        }
        
        // get all days to true if hartal
        
        for(int j = 1; j <= days; j++){
            if(j % 6 == 0 || j % 7 == 0) *(D + j - 1) = false;
        }
        
        // get Saturday and Friday false
        
        for(int j = 0; j < days; j++){
            if(*(D + j) == true) N++;
        }
        
        // count Hartals
        
        printf("%d\n", N);
        N = 0;
        free(D);
        free(h);
        
        // remember to free
    }
    
    return 0;
}

這題讓我醒腦我覺得剛剛好?
雖然應該還是算簡單啦
不然早就難到哭了

希望明天開始可以繼續持續練習和更新了
而且這學期會開始上java
然後希望可以加簽到C#
還有其他課
早上能多修一些是一些
再多拿幾次獎學金

早早達到畢業門檻
早早開始當社畜之類的

創作回應

更多創作