結果

問題 No.5 数字のブロック
ユーザー fumi6328
提出日時 2018-07-01 14:35:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 512 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-01 01:11:39
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d",&L);
      |         ~~~~~^~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                 scanf("%d",&W[i]);
      |                 ~~~~~^~~~~~~~~~~~
main.cpp:31:30: warning: ‘judge’ may be used uninitialized [-Wmaybe-uninitialized]
   31 |                 for(k=0;judge>0;++k){
      |                         ~~~~~^~

ソースコード

diff #

#include<stdio.h>

int main()
{
	int L,N,W[10000];
	int i,j,k;
	int tmp;
	int sum=0;
	int judge;
//入力
	scanf("%d",&L);
	scanf("%d",&N);
	for(i=0;i<N;++i){
		scanf("%d",&W[i]);
	}
//並び替え(小さい順)
	for(i=0;i<N;++i){
		for(j=i+1;j<N;++j){
			if(W[i]>W[j]){
				tmp=W[i];
				W[i]=W[j];
				W[j]=tmp;
			}
		}
	}
//判定
	if(L==W[0]){
		k=1;
		printf("%d",k);
	}else{
		for(k=0;judge>0;++k){
			sum=sum+W[k];
			judge=L-sum;
		}
		if(judge<0)
			k=k-1;
		printf("%d",k);
	}
//出力

	
	return 0;
}
0