char array solution,i got 90 for 2 10,still wa #1
#include<stdio.h>
#include<stdio.h>
void plus(char *a,char *b,char *c)
{
char *p1,*p2,*p3;
p1=a+99;
p2=b+99;
p3=c+99;
while(*p1!=0||*p2!=0)
{
*p3+=*p1+*p2-2*'0';
if(*p3>'9')
{
*p3-=10;
*(p3-1)+=1;
}
p1--;
p2--;
p3--;
}
}
void multi(unsigned char *s,int k)
{
unsigned char *p;
p=s+99;
while(*p!='0')
{
*p+=(*p-'0')*(k-1);
p--;
}
p=s+99;
while(*p!='0')
{
while(*p>'9')
{
*p-=10;
*(p-1)+=1;
}
p--;
}
}
void main()
{
unsigned char a[101],b[101],c[101],d[101];
int n,k,i,j;
for(i=0;i<100;i++)
{
a[i]=b[i]=c[i]=d[i]='0';
}
scanf("%d %d",&n,&k);
k-=1;
a[100]='\0';
b[100]='\0';
c[100]='\0';
a[99]=k+'0';
b[99]=(k+k*k)%10+'0';
b[98]=(k+k*k)/10+'0';
for(i=1;i<n-1;i++)
{
strcpy(c,d);
plus(a,b,c);
multi(c,k);
strcpy(a,b);
strcpy(b,c);
}
i=0;
while(*(b+i)=='0')
{
i++;
}
printf("%s",b+i);
}
Re: char array solution,i got 90 for 2 10,still wa #1
no matter right or wrong, bad code