結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2015-11-23 03:48:08 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 183 ms / 5,000 ms |
| コード長 | 474 bytes |
| コンパイル時間 | 115 ms |
| コンパイル使用メモリ | 21,760 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-18 07:50:15 |
| 合計ジャッジ時間 | 2,196 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:10:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d%d", &l, &n);
| ^~~~~~~~~~~~~~~~~~~~~
main.c:13:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d", &pw[i]);
| ^~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int main(){
int l, n, tmp;
int *pw;
int i;
int swap_f;
scanf("%d%d", &l, &n);
pw = (int *)malloc(n*sizeof(int));
for(i=0; i<n; ++i){
scanf("%d", &pw[i]);
}
do{
swap_f=0;
for(i=0; i<n-1; ++i){
if(pw[i]>pw[i+1]){
tmp=pw[i];
pw[i]=pw[i+1];
pw[i+1]=tmp;
swap_f=1;
}
}
}while(swap_f==1);
for(i=0; i<n; ++i){
l-=pw[i];
if(l<0)break;
}
printf("%d\n", i);
return 0;
}