POJ 2389 Bull Math(大数相乘)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13920 | Accepted: 7192 | 
Description
FJ asks that you do this yourself; don't use a special library function for the multiplication.
Input
Output
Sample Input
11111111111111 1111111111
Sample Output
12345679011110987654321
#include<stdio.h>
#include<string.h>
int main()
{
    char a[45],b[45];
    int s[90];
    while(scanf("%s%s",a,b)!=EOF)
    {
        int i,j,k,s1,s2;
        s1=strlen(a);
        s2=strlen(b);
        for(i=0; i<s1+s2; i++)
            s[i]=0;
        for(i=0; i<s1; i++)
            for(j=0; j<s2; j++)
            {
                s[i+j+1]=s[i+j+1]+(a[i]-'0')*(b[j]-'0');
            }
        for(i=s1+s2-1; i>=0; i--)
            if(s[i]>=10)
            {
                s[i-1]=s[i-1]+s[i]/10;
                s[i]=s[i]%10;
            }
        i=0;
        while(s[i]==0)
            i++;
        for(; i<s1+s2; i++)
            printf("%d",s[i]);
        printf("\n");
    }
    return 0;
}
                    
                
                
            
        
浙公网安备 33010602011771号