結果

問題 No.5 数字のブロック
ユーザー takatowin
提出日時 2017-01-07 15:52:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 534 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 10:50:42
合計ジャッジ時間 2,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   scanf("%d %d",&L,&N);
      |   ~~~~~^~~~~~~~~~~~~~~
main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%d",&b[i]);
      |     ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int L,N;
void bubble(int* b){
  int i,j,temp;
  for(i=N-1;i>0;i--){
    for(j=0;j<i;j++)
      if(b[j]>b[j+1]){
        temp=b[j];
        b[j]=b[j+1];
        b[j+1]=temp;
      }
  }
}
int main(void){
  int i=0,temp=0,temp1=0;
  scanf("%d %d",&L,&N);
  int b[N];
  for(;i<N;i++){
    scanf("%d",&b[i]);
  }
  bubble(b);
  for(i=0;i<N;i++){
    temp+=b[i];
    temp1++;
    if(temp>L){
      temp1--;
      break;
    }
  }
  printf("%d\n",temp1);
return 0;
}
0