結果

問題 No.3 ビットすごろく
ユーザー tsukacchan
提出日時 2016-06-03 21:28:18
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 497 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 20,864 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 06:43:55
合計ジャッジ時間 1,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:12:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 | scanf("%d",&N);
      | ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int fnBitCount(int);

int main(void){
    
int N;
int location=1; 
int bit=0;      
int times=1;    

scanf("%d",&N);

while(location != N)
{
	bit = fnBitCount(location);
	if((bit+location) <= N) location += bit;
	else					location -= bit;
	
	if(times >= 10000){
	printf("-1");
	break;
	}
	times++;
}

if(times < 10000)
printf("%d",times-1);

return 0;   
    
}

int fnBitCount(int n)
{
int bit_counter=0;
while(n>=1)
{
	if(n%2==1)bit_counter++;
	n/=2;
}
return bit_counter;
}
0