hdu 4207

http://acm.hdu.edu.cn/showproblem.php?pid=4207

两个数都不会超过六位数 所以可以直接用64位int 不会溢出

只要注意输出格式 就好了

#include<iostream>
#include<string.h>
using namespace std;
__int64 a;
int max1;
int count(__int64 x)
{
    int t=0;
    while(x)
    {
        x/=10;
        t++;
    }
    return t;
}
void solve(int temp,int c,int p)
{
    __int64 v,i,ans;
   
    if(c==-1)
    {
        c=0;
        ans=temp;
        v=count(temp);
    }
    else
    {
        ans=temp*a;
        v=count(ans);
       
    }
    for(i=max1-v-c;i>0;i--)
        printf(" ");
    printf("%I64d",ans);
    while(p--)
        printf("0");
    printf("\n");
}

int main()
{
    int i,j,temp,c,u=1;
    __int64 ans,b,t;
    while(scanf("%I64d%I64d",&a,&b))
    {
        if(a==0&&b==0)
            break;
        printf("Problem %d\n",u++);
        t=b;c=0;
        max1=count(a*b);
        solve(a,-1,0);
        solve(b,-1,0);
        for(i=0;i<max1;i++)
            printf("-");
        printf("\n");
        int p=0;
        int m=0;
        while(t)
        {
            temp=t%10;
            if(temp)
            {   m++;
                solve(temp,c,p);
                p=0;
            }
            else
                p++;
            t/=10;
            c++;
        }
        if(m==1)
            continue;
        for(i=0;i<max1;i++)
            printf("-");
        printf("\n");
        printf("%I64d\n",a*b);
    }
    return 0;
}
       

   

原文地址:https://www.cnblogs.com/assult/p/3051789.html