turbo pascal题目:
有一个8位的自然数,试求它最右边的第一个非0数字,和该数字的右边有几个0。(不要用到string)。...
有一个8位的自然数,试求它最右边的第一个非0数字,和该数字的右边有几个0。(不要用到string)。
展开
展开全部
const
num:array [0..9] of string[2]
=('〇','一','二','三','四','五','六','七','八','九');
wei:array [1..4] of string[2]
=('','十','百','千');
wy:array [1..2] of string[2]
=('万','亿');
liang:string[2]='两';
dian:string[2]='点';
(*
const
num:array [0..9] of string[2]
=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
wei:array [1..4] of string[2]
=('','拾','佰','仟');
wy:array [1..2] of string[2]
=('万','亿');
liang:string[2]='贰';
dian:string[2]='点';
*)
(*
const
num:array [0..9] of string[2]
=('0','1','2','3','4','5','6','7','8','9');
wei:array [1..4] of string[2]
=('','S','B','Q');
wy:array [1..2] of string[2]
=('W','Y');
liang:string[2]='L';
dian:string[2]='.';
*)
function shushu(n:string):string;
var
i,f,l:byte;
s,t:string;
z,r:boolean;
function shu4(n:string):string;
var
i,f,l:byte;
s:string;
begin
while length(n)<4 do n:='0'+n;
if n='0000' then begin
z:=true;shu4:='';exit;
end;
l:=4;while n[l]='0' do l:=l-1;
f:=1;while n[f]='0' do f:=f+1;
s:='';
for i:=1 to 4 do
if (n[i]<>'0') then begin
if z then s:=s+num[0];
if (i<>3) or (n[i]<>'1') or (copy(n,1,2)<>'00') or z then s:=s+num[ord(n[i])-48];
s:=s+wei[5-i]; r:=false; z:=false;
end else if i<l then z:=not r;
shu4:=s;
end;
function qww(n:byte):string;
var
s:string;
begin
s:='';
if n<>0 then begin
if n mod 2=1 then s:=s+wy[1];
while n>1 do begin s:=s+wy[2]; n:=n-2; end;
end;
qww:=s;
end;
begin
while (length(n)>0) and (n[1]='0') do n:=copy(n,2,length(n)-1);
if n='' then begin shushu:=num[0]; exit; end;
z:=false; r:=true; s:='';
for i:=1 to (length(n)+3) div 4 do begin
if i=1 then t:=copy(n,1,(length(n)-1) mod 4+1)
else t:=copy(n,(length(n)-1) mod 4+i*4-6,4);
t:=shu4(t);
s:=s+t;
if t<>'' then s:=s+qww((length(n)+3) div 4-i);
end;
i:=1; while i<=length(s)-length(wei[4]) do begin
if copy(s,i,length(num[2]))=num[2] then
if (copy(s,i+length(num[2]),length(wei[4]))=wei[4]) or
((copy(s,i+length(num[2]),length(wy[1]))=wy[1]) and (i=1)) or
((copy(s,i+length(num[2]),length(wy[2]))=wy[2]) and (i=1)) then begin
delete(s,i,length(num[2]));
insert(liang,s,i);
i:=i+2;
end;
i:=i+2;
end;
shushu:=s;
end;
function shushud(n:string):string;
var
s:string;
i:byte;
begin
if pos('.',n)=0 then begin
shushud:=shushu(n);
exit;
end else begin
s:=shushu(copy(n,1,pos('.',n)-1));
s:=s+dian;
for i:=pos('.',n)+1 to length(n) do
s:=s+num[ord(n[i])-48];
shushud:=s;
end;
end;
var s:string;
begin
readln(s);
writeln(shushud(s));
end.
num:array [0..9] of string[2]
=('〇','一','二','三','四','五','六','七','八','九');
wei:array [1..4] of string[2]
=('','十','百','千');
wy:array [1..2] of string[2]
=('万','亿');
liang:string[2]='两';
dian:string[2]='点';
(*
const
num:array [0..9] of string[2]
=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
wei:array [1..4] of string[2]
=('','拾','佰','仟');
wy:array [1..2] of string[2]
=('万','亿');
liang:string[2]='贰';
dian:string[2]='点';
*)
(*
const
num:array [0..9] of string[2]
=('0','1','2','3','4','5','6','7','8','9');
wei:array [1..4] of string[2]
=('','S','B','Q');
wy:array [1..2] of string[2]
=('W','Y');
liang:string[2]='L';
dian:string[2]='.';
*)
function shushu(n:string):string;
var
i,f,l:byte;
s,t:string;
z,r:boolean;
function shu4(n:string):string;
var
i,f,l:byte;
s:string;
begin
while length(n)<4 do n:='0'+n;
if n='0000' then begin
z:=true;shu4:='';exit;
end;
l:=4;while n[l]='0' do l:=l-1;
f:=1;while n[f]='0' do f:=f+1;
s:='';
for i:=1 to 4 do
if (n[i]<>'0') then begin
if z then s:=s+num[0];
if (i<>3) or (n[i]<>'1') or (copy(n,1,2)<>'00') or z then s:=s+num[ord(n[i])-48];
s:=s+wei[5-i]; r:=false; z:=false;
end else if i<l then z:=not r;
shu4:=s;
end;
function qww(n:byte):string;
var
s:string;
begin
s:='';
if n<>0 then begin
if n mod 2=1 then s:=s+wy[1];
while n>1 do begin s:=s+wy[2]; n:=n-2; end;
end;
qww:=s;
end;
begin
while (length(n)>0) and (n[1]='0') do n:=copy(n,2,length(n)-1);
if n='' then begin shushu:=num[0]; exit; end;
z:=false; r:=true; s:='';
for i:=1 to (length(n)+3) div 4 do begin
if i=1 then t:=copy(n,1,(length(n)-1) mod 4+1)
else t:=copy(n,(length(n)-1) mod 4+i*4-6,4);
t:=shu4(t);
s:=s+t;
if t<>'' then s:=s+qww((length(n)+3) div 4-i);
end;
i:=1; while i<=length(s)-length(wei[4]) do begin
if copy(s,i,length(num[2]))=num[2] then
if (copy(s,i+length(num[2]),length(wei[4]))=wei[4]) or
((copy(s,i+length(num[2]),length(wy[1]))=wy[1]) and (i=1)) or
((copy(s,i+length(num[2]),length(wy[2]))=wy[2]) and (i=1)) then begin
delete(s,i,length(num[2]));
insert(liang,s,i);
i:=i+2;
end;
i:=i+2;
end;
shushu:=s;
end;
function shushud(n:string):string;
var
s:string;
i:byte;
begin
if pos('.',n)=0 then begin
shushud:=shushu(n);
exit;
end else begin
s:=shushu(copy(n,1,pos('.',n)-1));
s:=s+dian;
for i:=pos('.',n)+1 to length(n) do
s:=s+num[ord(n[i])-48];
shushud:=s;
end;
end;
var s:string;
begin
readln(s);
writeln(shushud(s));
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2022-11-02 广告
2022-11-02 广告
Qi 1.3版本测试?您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、...
点击进入详情页
本回答由微测检测5.10提供
展开全部
var
a:array[1..8] of integer;
n,x,s:longint;
begin
readln(n);
s:=0;
for i:=1 to 8 do
begin
a[i]:=n mod 10;
n:=n div 10;
end;
for i:=1 to 8 do if a[i]<>0 then begin writeln(a[i]) break; end;(第一个非0数字)
for i:=1 to 8 do if a[i]=0 then s:=s+1 else break;
writeln(s);
end.
a:array[1..8] of integer;
n,x,s:longint;
begin
readln(n);
s:=0;
for i:=1 to 8 do
begin
a[i]:=n mod 10;
n:=n div 10;
end;
for i:=1 to 8 do if a[i]<>0 then begin writeln(a[i]) break; end;(第一个非0数字)
for i:=1 to 8 do if a[i]=0 then s:=s+1 else break;
writeln(s);
end.
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var a:longint;
i,j,k,s:integer;
begin
writeln('input a numer');
readln(a);
k:=0;
s:=0;
for i:=1 to 8 do begin
j:=a mod (i*10);
if j=0 then s:=s+1 else begin k:=j; break; end;
end;
writeln('0 you ',s,'shuzi',k);
end.
i,j,k,s:integer;
begin
writeln('input a numer');
readln(a);
k:=0;
s:=0;
for i:=1 to 8 do begin
j:=a mod (i*10);
if j=0 then s:=s+1 else begin k:=j; break; end;
end;
writeln('0 you ',s,'shuzi',k);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询