結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2016-09-30 16:07:42 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 131 ms / 5,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 109 ms |
コンパイル使用メモリ | 21,760 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 09:45:04 |
合計ジャッジ時間 | 1,852 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:7:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d", &L); | ^~~~~~~~~~~~~~~ main.c:8:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d", &N); | ^~~~~~~~~~~~~~~ main.c:12:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d", &W[i]); | ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> int main(void) { int L, N, i, j, k, temp, count, length; scanf("%d", &L); scanf("%d", &N); //printf("%d\n", N); int *W = malloc(sizeof(int) * N); for (i = 0; i < N; i++) { scanf("%d", &W[i]); //printf("a\n"); } /*for(i = 0; i < N; i++) { printf("%d ", W[i]); }*/ //printf("bb\n"); /*for (i = 0; i < N; N++) { printf("%d ", W[i]); } printf("\n");*/ for (i = 0; i < N - 1; i++) { for (j = 0; j < N - i - 1; j++) { if (W[j] > W[j + 1]) { temp = W[j]; W[j] = W[j + 1]; W[j + 1] = temp; } } /*for (k = 0; k < N; k++) { printf("%d ", W[k]); } printf("\n");*/ } /*printf("After Sorting\n"); for (i = 0; i < N; i++) { printf("%d ", W[i]); } printf("\n");*/ i = 0; length = 0; while ((N > i) && ((length += W[i]) <= L)) { i++; } printf("%d\n", i); free(W); return 0; }