娄山中学noip吧 关注:137贴子:1,769
  • 10回复贴,共1

今天作业贴还没开啊,答案就先放这儿吧

只看楼主收藏回复

加法:var
i,j,l,k,x,p,q:byte;
s,w,s1,s2,w1,w2:string;
a,b:array[1..100000] of longint;
begin
while not eof do begin
readln(s);
readln(w);
p:=0;
q:=0;
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
l:=0;
k:=0;
x:=0;
i:=0;
j:=0;
for i:=1 to length(s) do if s[i]='.' then begin p:=i; break; end;
for i:=1 to length(w) do if w[i]='.' then begin q:=i; break; end;
if p<>0 then begin s1:=copy(s,1,p-1); s2:=copy(s,p+1,length(s)); end;
if q<>0 then begin w1:=copy(w,1,q-1); w2:=copy(w,q+1,length(w)); end;
if p=0 then s1:=s;
if q=0 then w1:=w;
if (p<>0) and (q<>0) then begin
if length(s2)>length(w2) then begin
l:=length(s2); k:=length(w2);
for i:=1 to l-k do
w2:=w2+'0';
end
else begin
l:=length(s2); k:=length(w2);
for i:=1 to k-l do
s2:=s2+'0';
l:=k;
end;
for i:=l downto 1 do
if ord(s2[i])+ord(w2[i])-96+j>9 then begin
b[i]:=ord(s2[i])+ord(w2[i])+j-106;
j:=1;
end
else begin
b[i]:=ord(s2[i])+ord(w2[i])+j-96;
j:=0;
end;
x:=l;
end;
if length(s1)>length(w1) then begin
l:=length(s1); k:=length(w1);
for i:=1 to l-k do
w1:='0'+w1;
end
else begin
l:=length(s1); k:=length(w1);
for i:=1 to k-l do
s1:='0'+s1;
l:=k;
end;
a[l]:=a[l]+j;
j:=0;
for i:=l downto 1 do
if ord(s1[i])+ord(w1[i])-96+j+a[i]>9 then begin
a[i]:=a[i]+ord(s1[i])+ord(w1[i])+j-106;
j:=1;
end
else begin
a[i]:=a[i]+ord(s1[i])+ord(w1[i])+j-96;
j:=0;
end;
if j<>0 then write(j);
for i:=1 to l do write(a[i]);
if (p<>0) or (q<>0) then write('.');
if (p<>0) and (q<>0) then for i:=1 to x do write(b[i])
else if (p=0) and (q<>0) then write(w2)
else if (p<>0) and (q=0) then write(s2);
writeln;
end;
乘法var
i,j,l,k:byte;
s,w:string;
a:array[1..1000000] of longint;
begin
while not eof do begin
readln(s);
readln(w);
fillchar(a,sizeof(a),0);
for k:=length(w) downto 1 do begin
j:=0;
for i:=length(s) downto 1 do
if (ord(s[i])-48)*(ord(w[k])-48)+j>9 then begin
a[i+k]:=a[i+k]+(ord(s[i])-48)*(ord(w[k])-48) div 10;
a[i+k-1]:=a[i+k-1]+((ord(s[i])-48)*(ord(w[k])-48)+j) mod 10
end
else begin
a[i+k-1]:=a[i+k-1]+(ord(s[i])-48)*(ord(w[k])-48);
end;
end;
for i:=1 to length(s)+length(w)-1 do write(a[i]);
if a[length(s)+length(w)]<>0 then write(a[length(s)+length(w)]);
writeln;
end;
end.
end.


IP属地:美国1楼2012-05-16 19:36回复
    --凸


    IP属地:上海2楼2012-05-16 19:54
    回复
      鄙视你


      IP属地:上海3楼2012-05-16 19:55
      回复
        1楼没办法回复,不过恭喜你,两道都做对了


        4楼2012-05-17 17:35
        回复
          钱锟var
          i,j,k:char;
          begin
          for i:='a' to 'b' do
          for j:='a' to 'b' do
          for k:='a' to 'b' do
          if (i<>j) and (i<>k) and (k<>j) than writeln('i','j','k');
          readln
          end.


          5楼2012-05-18 20:00
          回复
            正确


            6楼2012-05-19 07:48
            回复
              正确啦


              7楼2012-05-20 07:27
              回复
                (1)var
                i,j,k:char;
                begin
                for i:='a' to 'd' do
                for j:='a' to 'd' do
                for k:='a' to 'd' do
                if (i<>j) and (j<>k) and (k<>i) then writeln(i,j:3,k:3);
                readln;
                end.
                (2)var
                i,j,k:char;
                begin
                for i:='1' to '5' do
                for j:='1' to '5' do
                for k:='1' to '5' do
                readln;
                end.
                (3)var
                i,j,k:char;
                begin
                for i:='a' to 'b' do
                for j:=chr(ord(i)+1) to 'c' do
                for k:=chr(ord(j)+1) to 'd' do writeln(i,j,k);
                readln;
                end.


                IP属地:广东8楼2012-05-20 18:36
                回复
                  完全正确


                  9楼2012-05-22 17:23
                  回复
                    彭润
                    var i,j,k:char;
                    begin for i:='a' to 'b' do
                    for j:=succ(i) to 'c' do
                    for k:=succ(j) to 'd' do writeln(i,j:2,k:2);
                    readln
                    end.


                    10楼2012-05-24 21:24
                    回复
                      对咯


                      11楼2012-05-26 07:19
                      回复