ETH官方钱包

前往
大廳
主題

[OJ練習] 382、483 不難但好麻煩ww

テリ君(桃夫模式) | 2023-01-05 13:13:52 | 巴幣 0 | 人氣 223

382(1/5)
學了個新招就是用log判斷數字長度,其他就是常見的判斷和因數分析

#include <stdio.h>
#include <math.h>

int main(){
    float num[101], test = 0;
    int N = 0;
    int temp;
    // num for num in every N, N for test cases; test for scan factor.
    while(scanf("%f", &num[N]) && num[N] != 0){
        if(num[N] > 60000) return 0;
        N++;
        if(N > 100) return 0;
    }
    printf("PERFECTION OUTPUT\n");
    
    for(int i = 0; i < N; i++){
        for(float j = 1; j < num[i]; j++){
            temp = j;
            if((int)num[i] % temp == 0){
                test = test + j;
            }
        }
        for(int k = 0; k < 5 - ceil(log10(num[i])); k++){
            printf(" ");
        }
        if(test < num[i]){
            printf("%.0f  DEFICIENT\n", num[i]);
        }
        else if(test == num[i]){
            printf("%.0f  PERFECT\n", num[i]);
        }
        else{
            printf("%.0f  ABUNDANT\n", num[i]);
        }
        test = 0;
    }
    
    printf("END OF OUTPUT\n");
    
    return 0;
}

483(1/5)
字串的倒轉,就排版麻煩而已,要腦內模擬

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

#define MAX_len 256
#define MAX_num 256

int main(){
    char line[MAX_len];
    int cnum[MAX_num], s_len;
    bool f = false;
    while(scanf("%s", line) != EOF){
        s_len = strlen(line);
        for(int i = 0; i <= s_len; i++){
            if(f == false) f = true;
            else printf("%c", line[s_len - i]);
        }
        if(line[s_len - 1] == '.'){
            printf("\n");
            f = false;
        }
         
    }
    
    return 0;
}

我發現要多做這種訓練,雖然麻煩但經驗累積和不同題型排列的刺激是必要的。
不過我最近都好容易累喔= =
是不是要再更加督促自己的健康之類的= =


創作回應

更多創作