結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2018-08-30 20:59:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,029 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 24,320 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-13 20:34:13 |
合計ジャッジ時間 | 2,447 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d",&L); | ~~~~~^~~~~~~~~ main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d",&Wi[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> void bubble_sort(int *data, int n){ int i,x; bool flag = false; while(flag == false){ flag = true; for(i=0; i<n-1; i++){ if(data[i] > data[i+1]){ x = data[i]; data[i] = data[i+1]; data[i+1] = x; flag = false; } } } } int main(void){ int L,N,i,sum; int *Wi; scanf("%d",&L); scanf("%d",&N); Wi = (int*)malloc(N*sizeof(int)); for(i=0; i<N; i++){ scanf("%d",&Wi[i]); } bubble_sort(Wi,N); i=0; sum=0; do { sum += Wi[i]; printf("%d\n",sum); if(sum > L) i--; } while (++i <= N && sum <= L); printf("%d",i); /* for(i=0,sum=0; i<N && sum<=L; i++){ sum += Wi[i]; } if(i==N){ printf("%d",i); } else { printf("%d",i-1); // ぴったり入って ブロックの余り個数が1の時??? } */ free(Wi); return 0; }