错的莫名其妙,找出错的都是大佬

P1303 A*B Problem

XYC的Ship @ 2019-08-24 21:33:00

#include<bits/stdc++.h>
using namespace std;
char a[1100],a1[1100],b[1100],b1[1100],c[1100];
int main()
{
    gets(a1);
    gets(b1);
    int jw=0,la=strlen(a1),lb=strlen(b1);
    for(int i=0;i<la;i++)
    {
        a[la-i]=a1[i]-48;
    }
    for(int i=0;i<lb;i++)
    {
        b[lb-i]=b1[i]-48;
    }
    for(int i=1;i<=la;i++)
    {
        jw=0;
        for(int j=1;j<=lb;j++)
        {
            c[i+j-1]=c[i+j-1]+a[i]*b[j]+jw;
            jw=c[i+j-1]/10;
            c[i+j-1]=c[i+j-1]%10;
        }
        c[i+lb]=jw;
    }
    int lc=la+lb;
    while(c[lc]==0&&lc>1)
    {
        lc--;
    }
    for(int i=lc;i>=1;i--)
    {
        cout<<char(c[i]+48);
    }
    return 0;
}

by 树套树 @ 2019-08-24 21:37:01

好营销号的标题


by hyfhaha @ 2019-08-24 21:44:04

您就不能用py吗


by 常青藤 @ 2019-08-24 22:07:51

高精度难道不是要右对齐吗?

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxN=3020;
int a[maxN+1],b[maxN+1],c[maxN+1]={0};
void read(int []);
void multi(int [],int []);
void write();
int main()
{
    read(a); read(b);
    multi(a,b);
    write();
    return 0;
}
void read(int a[])
{
    char ch=getchar(); int len=0;
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) {a[len++]=ch-'0'; ch=getchar();}
    for(int i=maxN;i>=0;i--)
        if(len>0) a[i]=a[--len];
        else a[i]=0;
}
void multi(int a[],int b[])
{
    int k,t;
    for(int i=maxN;i>maxN/2;i--)
    {
        k=0; t=i;
        for(int j=maxN;j>maxN/2;j--)
        {
            c[t]+=a[i]*b[j]+k;
            k=c[t]/10;
            c[t--]%=10;
        }
        c[t--]=k;   
    }
}
void write()
{
    int i=0;
    while(c[i]==0 && i<maxN) i++;
    while(i<=maxN) printf("%d",c[i++]);
}

|