using namespace std;
int *func(int *x,char a);
int main()
{
int zhiShu[8]={2,3,5,7,11,13,17,19};
int a[8]={0};int b[8]={0};int c[8]={0};
int *pA=func(a,’+’);
int *pB=func(b,’\n’);
for(int i=0;i<8;i++)
{
if(--pA>=a)c[i]+=*pA;
if(--pB>=b)c[i]+=*pB;
if(c[i]>=zhiShu[i])
{
int temp=c[i]/zhiShu[i];
c[i+1]+=temp;
c[i]%=zhiShu[i];
}
}
int *pC=&c[8];
while(0==*--pC);
for(;pC>=c;pC--)
{
cout<<*pC;
if(pC!=c)cout<<",";
}
return 0;
}
int *func(int *x,char a)
{
char cTemp=’\0’;
while(cTemp!=a)
{
cTemp=cin.get();
if(’,’==cTemp)continue;
else if(’1’==cTemp)
{
cTemp=cin.get();
if(cTemp==’0’)*x++=10;
else *x++=1;
}
else if(cTemp!=’+’&&cTemp!=’\n’)*x++=cTemp-’0’;
}
return x;
}
310题
帮我改对了送分.
哥賞你个程序,你自己研究去吧!!
const ww:array[1..5] of integer=(2,3,5,7,11);
var s,s1,s2,s0:string;
i,j,m,n,k,l,t,co,t1,t2:longint;
a,b,c:array[1..1000] of longint;
begin
readln(s);
l:=length(s);
i:=pos(’+’,s);
s1:=copy(s,1,i-1);
s2:=copy(s,i+1,l-i);
k:=0;
t1:=0;
s1:=s1+’,’;
l:=length(s1);
for i:=1 to l do
if s1[i]=’,’ then
begin
s0:=’’;
inc(t1);
for j:=k+1 to i-1 do
s0:=s0+s1[j];
val(s0,a[t1],co);
k:=i
end;
k:=pos(’+’,s)-l;
t2:=0;
s2:=s2+’,’;
l:=length(s2);
for i:=1 to l do
if s2[i]=’,’ then
begin
s0:=’’;
inc(t2);
for j:=k+1 to i-1 do
s0:=s0+s2[j];
val(s0,b[t2],co);
k:=i
end;
if t1>t2 then t:=t1 else t:=t2;
for i:=1 to t1 do
c[t1-i+1]:=a[i];
for i:=1 to t1 do
a[i]:=c[i];
for i:=1 to t2 do
c[t2-i+1]:=b[i];
for i:=1 to t2 do
b[i]:=c[i];
for i:=1 to t do
a[i]:=a[i]+b[i];
for i:=1 to t do
begin
a[i+1]:=a[i+1]+a[i] div ww[i];
a[i]:=a[i] mod ww[i]
end;
if a[t+1]<>0 then write(a[t+1],’,’);
for i:=t downto 1 do
if i<>1
then write(a[i],’,’)
else write(a[i])
end.