Large number of divisions ... Hurry up, borrow the way of the ox people

Source: Internet
Author: User

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXLEN 200
int substract (int *p1,int *p2,int len1,int len2)
{
int i;
if (LEN1&LT;LEN2)
return-1;
if (LEN1==LEN2)
{
for (i=len1-1;i>=0;i--)
{
if (P1[i]>p2[i])
Break
else if (P1[i]<p2[i])
return-1;
}
}
for (i=0;i<=len1-1;i++)
{
P1[i]-=p2[i];
if (p1[i]<0)
{
p1[i]+=10;
p1[i+1]--;
}
}
for (i=len1-1;i>=0;i--)
if (P1[i])
return (I+1);
return 0;
}

int main ()
{
int n,k,i,j;
int len1,len2;
int ntimes;
int ntemp;
int Num_a[maxlen];
int Num_b[maxlen];
int Num_c[maxlen];
Char str1[maxlen+1];
Char str2[maxlen+1];

scanf ("%d", &n);
while (n--)
{
scanf ("%s", str1);
scanf ("%s", str2);

memset (num_a,0,sizeof (num_a));
memset (num_b,0,sizeof (Num_b));
memset (num_c,0,sizeof (Num_c));

Len1=strlen (STR1);
Len2=strlen (STR2);

for (j=0,i=len1-1;i>=0;j++,i--)
num_a[j]=str1[i]-' 0 ';
for (j=0,i=len2-1;i>=0;j++,i--)
num_b[j]=str2[i]-' 0 ';

if (LEN1&LT;LEN2)
{
printf ("0\n");
Continue
}
Ntimes=len1-len2;
for (i=len1-1;i>=0;i--)
{
if (i>=ntimes)
Num_b[i]=num_b[i-ntimes];
Else
num_b[i]=0;
}
Len2=len1;
for (j=0;j<=ntimes;j++)
{
while ((Ntemp=substract (num_a,num_b+j,len1,len2-j)) >=0)
{
Len1=ntemp;
num_c[ntimes-j]++;
}
}

for (i=maxlen-1;num_c[i]==0&&i>=0;i--);
if (i>=0)
for (; i>=0;i--)
printf ("%d", num_c[i]);
Else
printf ("0");
printf ("\ n");
}
return 0;
}

Large number of divisions ... Hurry up, borrow the way of the ox people

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.