結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2018-06-29 23:35:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 694 bytes |
コンパイル時間 | 129 ms |
コンパイル使用メモリ | 23,552 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-18 12:30:58 |
合計ジャッジ時間 | 2,174 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d",&l); | ~~~~~^~~~~~~~~ main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d",&w[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(void){ //lとnの読み取り int l,n; scanf("%d",&l); scanf("%d",&n); //wの読み込み int i,w[n]; for(i = 0 ; i < n ; i++){ scanf("%d",&w[i]); } //昇順に並べ替え int j,change; for(i = 0 ; i < n - 1 ; i++){ for(j = 0 ; j < n - i - 1 ; j++){ if(w[j] > w[j + 1]){ change = w[j]; w[j] = w[j + 1]; w[j + 1] = change; } } } //何個入るか数える int x; i = 0; x = 0; while(l >= 0 && i <= n){ l -= w[i]; i++; x++; } x--; printf("%d\n",x); return 0; }