結果

問題 No.138 化石のバージョン
ユーザー demudemu
提出日時 2015-06-01 00:49:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,727 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 26,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 13:26:00
合計ジャッジ時間 1,621 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int divide(char*)’:
main.cpp:6:34: warning: ‘sizeof’ on array function parameter ‘part’ will return size of ‘char*’ [-Wsizeof-array-argument]
     for (int i=0; i < sizeof(part); i++) {
                                  ^
main.cpp:4:17: note: declared here
 int divide(char part[10]) {
            ~~~~~^~~~~~~~

ソースコード

diff #

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

int divide(char part[10]) {
    int length = 0;
    for (int i=0; i < sizeof(part); i++) {
        if (part[i] != '\0') length++;
        else return length;
    }
    return length;
}

void separate(char org[2][30], char part[2][3][10], int length[2][3]) {

    for (int i = 0; i < 2; i++) {
        char* tp = strtok(org[i], ".");
        sprintf(part[i][0],"%s",tp);

        int count = 0;
        while (tp != NULL) {
            tp = strtok(NULL, ".");
            if (tp != NULL) {
                if (count++ == 0) sprintf(part[i][1], "%s", tp);
                else              sprintf(part[i][2], "%s", tp);
            }
        }
        for (int j=0; j<3; j++) length[i][j] = divide(part[i][j]);
    }
}

void bigger(char part[2][3][10], int length[2][3]) {
    for (int j=0; j < 3; j++) {
        if (length[0][j] > length[1][j]) {
            printf("YES\n");
            return;
        } else if (length[0][j] == length[1][j]) {
            for (int k =0; k < length[0][j]; k++) {
                if ((int) part[0][j][k] > (int) part[1][j][k]) {
                    printf("YES\n");
                    return;
                } else if ((int) part[0][j][k] < (int) part[1][j][k]) {
                    printf("NO\n");
                    return;
                }
            }
        } else {
            printf("NO\n");
            return;
        }
    }
    printf("YES\n"); // 全て等しいとき
}

int main() {
    int  sum[2] = {0,0};
    int  length[2][3] = {0};
    char version[2][30];
    char part[2][3][10]= {0};

    scanf("%s",&version[0]);
    scanf("%s",&version[1]);

    separate(version, part, length);
    bigger(part, length);
    return 0;
}
0