結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2017-03-01 10:30:42 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 201 ms / 5,000 ms |
| コード長 | 549 bytes |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 21,376 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 10:54:36 |
| 合計ジャッジ時間 | 2,626 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d%d",&BoxW,&N);
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:11:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d",&BlockW[i]);
| ^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(void)
{
int BoxW,N,BlockW[10000],i;
scanf("%d%d",&BoxW,&N);
for(i=0;i<N;i++){
scanf("%d",&BlockW[i]);
}
int j,temp;
for(i=0;i<N;i++){ /*昇順並び替え*/
for(j=i+1;j<N;j++){
if( BlockW[i] > BlockW[j] ){
temp= BlockW[i];
BlockW[i]=BlockW[j];
BlockW[j]=temp;
}
}
}
//for(i=0;i<N;i++) /*並び替え確認*/
//printf("%d\n",BlockW[i]);
int total=0;
int count=0;
for(i=0;i<N;i++){
total = total + BlockW[i];
if(total <= BoxW){
count++;
}else{
break;
}
}
printf("%d\n",count);
return 0;
}