結果

問題 No.99 ジャンピング駒
ユーザー NEEHATOVNEEHATOV
提出日時 2020-06-06 05:54:38
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,064 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 29,440 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-23 12:57:41
合計ジャッジ時間 1,977 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘Array_Collect’ 内:
main.c:9:21: 警告: ポインタと整数との比較を行なっています
    9 |         if ((tmp[i] != NULL)) {
      |                     ^~
main.c: 関数 ‘Array_Jump’ 内:
main.c:22:20: 警告: assignment to ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
   22 |             tmp[i] = NULL; tmp[i + 1] = NULL;
      |                    ^
main.c:22:39: 警告: assignment to ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
   22 |             tmp[i] = NULL; tmp[i + 1] = NULL;
      |                                       ^
main.c: 関数 ‘main’ 内:
main.c:30:25: 警告: initialization of ‘int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
   30 |     int tmp[20][100] = {NULL};
      |                         ^~~~
main.c:30:25: 備考: (‘tmp[0][0]’ 用の初期化付近)

ソースコード

diff #

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

int Array_Collect(const int N, int tmp[], int tmp2[])
{
    // 残っている数字をtmp配列にまとめる
    int j = 0,cnt = 0;
    for (int i = 0; i < N ; i++) {
        if ((tmp[i] != NULL)) {
            tmp2[j++] = tmp[i];
            cnt++;
        }
    }
    return cnt;
}
void Array_Jump(const int N, int tmp[])
{
    for (int i = 0; i < N; i++) {
        // 奇数偶数で隣り合うものを消去
        if ((tmp[i] % 2 == 0 && tmp[i + 1] % 2 != 0) ||
            (tmp[i] % 2 != 0 && tmp[i + 1] % 2 == 0)) {
            tmp[i] = NULL; tmp[i + 1] = NULL;
            i++;
        }
    }
}
int main() {

    int i = 0, j = 0, N;
    int tmp[20][100] = {NULL};
    scanf("%d", &N);
    int cnt = N - 1;
    for (i = 0; i < N ; i++) {
        scanf("%d", &tmp[0][i]);
    }
    
    i = 0;
    while (j++ < 10)
    {
        if (cnt > 1) {
            Array_Jump(cnt-1, tmp[i]);
            cnt = Array_Collect(N, tmp[i], tmp[i+1]);
            i++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}
0