以下の内容はhttps://ozy4dm.hateblo.jp/entry/20070228/p1より取得しました。


The Moronic Cowmpouter

http://acm.pku.edu.cn/JudgeOnline/problem?id=3191
10進整数が与えられて、それを基数-2として変換する問題。

  • 入力例
-13
  • 出力例
110111

計算方法は

 1*(-2)^5+1*(-2)^4+0*(-2)^3+1*(-2)^2+1*(-2)^1+1*(-2)^0
=1*(-32)+1*(+16)+0*(-8)+1*(+4)+1*(-2)+1*(+1)
=-32+16+4-2+1
=-13
char v[9];i;
main(n){
  for(n=atoi(gets());v[i++]=n%2?--n,49:48,n/=-2;);
    puts(strrev(v));
}

特に工夫はしていませんが、入力が0の時には注しなければーという感じでしょうか。




以上の内容はhttps://ozy4dm.hateblo.jp/entry/20070228/p1より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14