老师参与

函数部分的作业我好像不开窍哦

功夫熊猫POE 发表于2016年09月23日
<p>第六周作业第三题,第i位替换,我的程序总是显示“wrong answer”。但我怎么也不明白错在哪里了?我的程序如下:<br ></p><p>int a[i+3],b[i+3];</p><p>int c=n;int d=m;</p><p>for (int s=0;s&lt;=i;++s) { &nbsp;</p><p>if (c!=0){ &nbsp; &nbsp;</p><p>&nbsp; a[s]=c%2; &nbsp; &nbsp;</p><p>&nbsp; &nbsp;c=c/2;} &nbsp;</p><p>if (d!=0){ &nbsp; &nbsp;</p><p>&nbsp; b[s]=d%2; &nbsp; &nbsp;</p><p>&nbsp; d=d/2;}}</p><p>if (a[i]==b[i]) return n;</p><p>&nbsp; else { &nbsp;</p><p>&nbsp; &nbsp;a[i]=b[i];</p><p>&nbsp; &nbsp;for (int s=i;s&gt;=0;--s) {c=c*2+a[s];}</p><p>&nbsp; &nbsp;return c;}</p>
3 回复