2006-4-22 20:10
coldney
[破釜杯]编程大赛第一期(04.22-05.06)
[b]Lowest Bit[/b]
Given an positive integer A (1 <= A <= 100), output the integer which consists of the lowest bit of “1” and the rest bits of “0” in A.
For example, given A = 26, we can write A in binary form as “11010”, so the result is “10” in the form of binary, and the output should be 2.
Another example goes like this: given A = 88, we can write A in binary form as “1011000”, so the result is “1000”. And the output should be 8.
[b]Input[/b]
Each line of input contains only an integer A (1 <= A <= 100). A line containing a single "0" indicates the end of input, and this line is not a part of the input data.
[b]Output[/b]
For each A in the input, output a line containing only the integer which consists of the lowest bit of “1” and the rest bits of “0” in A.
[b]Sample Input[/b]
26
88
0
[b]Sample Output[/b]
2
8
2006-4-22 20:12
coldney
答案太巧妙了。
先不公布。
回答正确者,均奖PFB
并评出最优者,也奖PFB
具体的以后再说…………
2006-4-22 20:14
coldney
还有,诚信为本,不要借助任何搜索工具哦~~
2006-4-23 11:18
祥子
//将输入的的二进制字符串转换为需要的结果
function StrToDest(const Value: string): string;
//二进制转化十进制, 子函数
function BinToDec(const Value: string): string;
var
I, tmpResult, Base, N: ShortInt; //Base为底数,N为指数
begin
tmpResult := 0;
for I := Length(Value) downto 1 do
begin
Base := StrToInt(Value[I]);
N := Round(IntPower(2, Length(Value)-I));
tmpResult := tmpResult + Base*N;
end;
Result := IntToStr(tmpResult);
end;
var
Pos1: ShortInt;
ValueInt: Integer;
begin
Result := '';
ValueInt := StrToIntDef(Value, 0);
if (ValueInt <= 0) or (ValueInt > 1100100) then //判断输入是否合法,输入必需是1到100
begin
MessageDlg('输入超出范围,请重新输入', mtWarning, [mbOK], 0);
Exit;
end;
Result := Value;
while True do //删除最后一个1之前的所有数据
begin
Pos1 := Pos('1', Result);
if Pos1 = 0 then Break;
Delete(Result, 1, Pos1);
end;
Result := '1' + Result;
//将转换后的结果以十进制的字符串输出
Result := BinToDec(Result);
end;
2006-4-23 11:21
祥子
[s:2] [s:2]
给PFB
2006-4-23 16:09
木舟
支持, 多搞些基础一些的东西. 祥子是这个版块的版版, 可以直接给参赛者加分.
2006-4-23 16:54
祥子
OK.
灌水者加1分
2006-4-23 18:01
coldney
截止时间为5月6日。
其他人都没有兴趣吗?
2006-4-29 00:22
coldney
怎么都没其他人感兴趣啊?
下次不搞了
2006-4-29 10:25
祥子
我有兴趣啊 [s:2]
2006-5-12 00:17
xxg2
我是刚开始对语言感兴趣 不懂写的什么 但支持还是要得的 不然太冷清的 [s:18] [s:18] [s:18] [s:18] [s:18]
2006-5-13 21:11
coldney
本活动就告一段落吧。
等有兴趣的人多了再说
2006-5-13 21:19
祥子
那我的PFB呢? [s:2] [s:2]
2006-5-13 21:25
coldney
先公布一下参考答案:
[code]
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n>0)
{
int i=1;
while (i<n)
{
if ((n&i)>0) break;
i<<=1;
}
cout<<i<<endl;
cin>>n;
}
return 0;
}
[/code]
2006-5-14 20:47
coldney
[quote][b]引用第12楼[i]祥子[/i]于[i]2006-05-13 21:19[/i]发表的“”[/b]:
那我的PFB呢? [s:2] [s:2][/quote]
转帐成功!!
coldney使用转帐功能,转帐给祥子金额:100破釜币
2006-5-14 21:22
祥子
贪帐贪财~~
2006-5-23 22:45
lihuilogin
多搞些啊,还有有能力的都出来啊,大家一起学习一下
2007-6-30 14:15
qsingxiao
我也看看,自己还什么都不会呢
页:
[1]
Powered by Discuz! Archiver 5.5.0
© 2001-2006 Comsenz Inc.