PACAL大牛进若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数.例如:(13)10=(1101)2其中1的个数为3,0的个数为1

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 16:20:24
PACAL大牛进若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数.例如:(13)10=(1101)2其中1的个数为3,0的个数为1
xT_oV*͠x&4DG}0B510M-@BmhEaK6f ;8t:Bs_gkOӫ3z w?xN{Ñ7mL~\ ֻ<4xNz ~ JhrqǙ<Qc>{/f=Iyo;7յ**in9OXJ?"BcAA mP3Ě.I<5l}雳9 S6)X6$rBE +bQYV1N UAx"W0) d{(^]wSf)Rx@-+j۹f5vps(Gk߼ΕP+v}|7G}l7:'CiwvnɈ>\z 9

PACAL大牛进若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数.例如:(13)10=(1101)2其中1的个数为3,0的个数为1
PACAL大牛进
若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数.
例如:(13)10=(1101)2
其中1的个数为3,0的个数为1,则称此数为A类数;
(10)10=(1010)2
其中1的个数为2,0的个数也为2,称此数为B类数;
(24)10=(11000)2
其中1的个数为2,0的个数为3,则称此数为B类数;
程序要求:求出1~1000之中(包括1与1000),全部A、B两类数的个数.
输入一个数,求出1到这个数之间的AB类数
输出一行输出两个数,空格隔开.
帮我看看哪儿错了,
program f003;
var
n,i,a,b:longint;
function pd(x:longint):boolean;
var
a:array [1..10000] of longint;
m,i,k,n0,n1:longint;
begin
for i:=1 to 20 do a[i]:=-1;
while x0 do begin
inc(k);
m:=x mod 2;
x:=x div 2;
a[k]:=m;
end;
for i:=1 to n do begin
if a[i]=0 then inc(n0);
if a[i]=1 then inc(n1);
end;
if n1>n0 then pd:=true else pd:=false;
end;
begin
readln(n);
for i:=1 to n do
if pd(i) then inc(a) else inc(b);
writeln(a,' ',b);
end.

PACAL大牛进若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数.例如:(13)10=(1101)2其中1的个数为3,0的个数为1
program Project1;
const max=1000;
var e:string; b:string;
m,a,n,i,q,w:integer; t,d:integer;
begin
assign(output,'output.txt');
rewrite(output);
t:=0; d:=0;
for n:=1 to max do
begin
m:=n; q:=0; w:=0;
e:=''; b:='';
repeat {此处转二进制 }
a:=m mod 2 ;
str(a,b);
e:=b+e;
m:=m div 2;
b:='';
until m=0;
for i:=1 to length(e) do {此处求二进制中1和0的个数 }
if e[i]='1' then q:=q+1
else w:=w+1;
if q>w then t:=t+1
else d:=d+1;
end;
writeln('A: ',t);
write('B: ',d);
close(output);
end.
自己写的已经通过,答案是:
A: 538
B: 462