#Pascal#
看此题写题解者甚少,在下不才,也写了1份题解,希望大家能够有所帮助。
一拿到此题,我就觉得有点像高精度的感觉,都是用字符串来处理这一个问题。
做这道题需要注意的是,当两个字符串长度不想当是就应该用‘0’来补位,不然就会出现头对头加的情况,显然是WR
对于这道题来说,只需一位一位的相加即可。对数字与字符分别处理,当>n时需要进位,就可以做出来了
以下是pascal AC代码
```cpp
var n,i,k,p:longint;
s,s1,s2,t:string;
begin
readln(n);
readln(s);
readln(s1);
if (length(s)<length(s1)) or ((length(s)=length(s1)) and (s<s1)) then
begin t:=s; s:=s1; s1:=t; end;
if length(s1)<length(s) then
begin
t:='';
for i:=1 to length(s)-length(s1) do
t:=t+'0';
s1:=t+s1;
end;
for i:=length(s) downto 1 do
begin
if (s[i]>='0') and (s1[i]>='0') then
p:=ord(s[i])+ord(s1[i])+k
else begin if s[i]>='0' then p:=ord(s[i])+k;
if s1[i]>='0' then p:=ord(s1[i])+k; end;
k:=0;
if (s1[i]>='a') then p:=p-ord('a')+10;
if (s[i]>='a') then p:=p-ord('a')+10;
if ((s[i]>='0') and (s[i]<='9')) then p:=p-ord('0');
if ((s1[i]>='0') and (s1[i]<='9')) then p:=p-ord('0');
while p>=n do
begin
p:=p-n;
k:=k+1;
end;
if (p>=0) and (p<=9) then s2:=s2+chr(p+ord('0'));
if (p>=10) then s2:=s2+chr(p-10+ord('a'));
end;
if k>0 then s2:=s2+chr(k+ord('0'));
for i:=length(s2) downto 1 do
write(s2[i]);
end.
```
如有错误,还请指出