結果

問題 No.5 数字のブロック
ユーザー jin128
提出日時 2016-08-25 15:53:47
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 21,248 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 02:18:48
合計ジャッジ時間 1,248 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:15:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |   scanf("%d",&big);
      |   ^~~~~~~~~~~~~~~~
main.c:17:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   scanf("%d",&amo);
      |   ^~~~~~~~~~~~~~~~
main.c:22:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%d",&small[i]);
      |     ^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

int compare(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  int small[10001];
  int amo;
  int big;
  int sum = 0;

//  printf("input size of bigbox :");
  scanf("%d",&big);
//  printf("input the amount of smallboxes :");
  scanf("%d",&amo);
//  printf("input size of smallboxes\n");
  int i;
  for(i = 0; i < amo; i++){
//    printf("%d :",i+1);
    scanf("%d",&small[i]);
  }

  qsort(small, amo, sizeof(int), compare);

  int j = 0;
  while(j < amo && sum < big ){
    sum += small[j++];
  }

  printf("%d\n",j-1);
  return 0;
}
0