結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
Naoki00712
|
| 提出日時 | 2023-05-29 16:08:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 622 bytes |
| コンパイル時間 | 397 ms |
| コンパイル使用メモリ | 29,184 KB |
| 最終ジャッジ日時 | 2025-02-13 16:07:13 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d", &l);
| ~~~~~^~~~~~~~~~
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d", &w[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
static int cmp(const void* n1, const void* n2)
{
if (*(long*)n1 > *(long*)n2)
{
return 1;
}
else if (*(long*)n1 < *(long*)n2)
{
return -1;
}
else
{
return 0;
}
}
int main()
{
int l, n;
scanf("%d", &l);
scanf("%d", &n);
int* w;
w = (int*)malloc(sizeof(int) * n);
if (w)
{
for (int i = 0; i < n; i++)
{
scanf("%d", &w[i]);
}
//if (sizeof(w) != sizeof(int))
qsort(w, n, sizeof(int), cmp);
int i = 0, j = 0;
while (i < n)
{
j += w[i];
if (l < j)
{
break;
}
i++;
}
printf("%d", i);
}
free(w);
return 0;
}
Naoki00712