結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
nckpxx
|
| 提出日時 | 2018-08-30 17:59:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 752 bytes |
| コンパイル時間 | 157 ms |
| コンパイル使用メモリ | 24,448 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 19:51:02 |
| 合計ジャッジ時間 | 2,251 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 14 |
コンパイルメッセージ
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);
for(i=0,sum=0; i<N && sum<L; i++){
sum += Wi[i];
// printf("sum:%d\n",sum);
}
printf("%d",i-1);
free(Wi);
return 0;
}
nckpxx