結果
問題 | No.156 キャンディー・ボックス |
ユーザー |
|
提出日時 | 2015-11-17 00:16:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 742 bytes |
コンパイル時間 | 111 ms |
コンパイル使用メモリ | 23,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 15:44:39 |
合計ジャッジ時間 | 1,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d %d", &box, &candy); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d", &box_candy[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(void) { int box; int candy; int count = 0; int box_candy[10] = {0}; int tmp; int i, j; scanf("%d %d", &box, &candy); for ( i = 0; i < box; i++ ) { scanf("%d", &box_candy[i]); } for ( i = 0; i < box - 1; i++ ) { for ( j = 0; j < box - 1; j++ ) { if ( box_candy[j] >= box_candy[j+1] ) { tmp = box_candy[j]; box_candy[j] = box_candy[j+1]; box_candy[j+1] = tmp; } } } tmp = 0; for ( ;; ) { if ( candy != 0 ) { if ( box_candy[0+tmp] != 0 ) { box_candy[0+tmp]--; candy--; if ( box_candy[0+tmp] == 0 && candy == 0 ) { count++; break; } } else { tmp++; count++; } if ( candy == 0 ) { break; } } } printf("%d\n", count); }