結果
問題 | No.5 数字のブロック |
ユーザー |
|
提出日時 | 2019-09-08 12:01:26 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 814 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 21,760 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-27 14:53:29 |
合計ジャッジ時間 | 2,231 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 34 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:40:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | scanf("%d%d",&L,&N); | ^~~~~~~~~~~~~~~~~~~ main.c:45:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d",W+i); | ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> #define swap(type,x,y) do{type t=x;x=y;y=t;}while(0) void bubble(int *W,int N) { int i,j; for(i=0;i<N;i++){ int exchg=0; for(j=N-1;j>i;j--) if(W[j-1]>W[j]){ swap(int,W[j-1],W[j]); exchg++; } if(exchg==0)break; } } void count(int *W,int L,int cnt) { int i; for(i=0,cnt=0;L>0;i++){ printf("%d\n",W[i]); L-=W[i]; cnt++; if(L-W[i+1]<0) break; } } int main(void) { int i,cnt=0; int L,N; int *W; scanf("%d%d",&L,&N); W=calloc(N,sizeof(int)); for(i=0;i<N;i++) scanf("%d",W+i); bubble(W,N); count(W,L,cnt); printf("%d\n",cnt); return 0; }