ETH官方钱包

切換
舊版
前往
大廳
主題

[OJ練習(xí)] 12577、10050 重新開(kāi)始更新!! 我是鬼吧(欸?

テリ君(桃夫模式) | 2023-02-20 16:19:42 | 巴幣 4 | 人氣 247

GitHub
12577(1/5)
感覺(jué)有點(diǎn)偷吃步
請(qǐng)問(wèn)這個(gè)是阿拉花瓜的概念ㄇ?

#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)
有偷看一下題意解釋
怕理解錯(cuò)
但我是鬼吧
一個(gè)月沒(méi)碰腦袋剛開(kāi)機(jī)而已
code和註解打完一次就過(guò)
舒服

#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;
}

這題讓我醒腦我覺(jué)得剛剛好?
雖然應(yīng)該還是算簡(jiǎn)單啦
不然早就難到哭了

希望明天開(kāi)始可以繼續(xù)持續(xù)練習(xí)和更新了
而且這學(xué)期會(huì)開(kāi)始上java
然後希望可以加簽到C#
還有其他課
早上能多修一些是一些
再多拿幾次獎(jiǎng)學(xué)金

早早達(dá)到畢業(yè)門檻
早早開(kāi)始當(dāng)社畜之類的

創(chuàng)作回應(yīng)

更多創(chuàng)作