【求助】大红大紫

P1303 A*B Problem

添哥 @ 2020-07-15 20:07:25

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char a[2001],b[2001];
    int c[4001]={0},lena,lenb,d=0;
    cin>>a>>b;
    lena=strlen(a)-1;
    lenb=strlen(b)-1;
    for(int i=0;i<=lena;i++)
    {
        for(int j=0;j<=lenb;j++)
        {
            c[i+j]+=(a[i]-'0')*(b[i]-'0')/10;
            if(c[i+j]>=10)
            {
                c[i+j+1]+=c[i+j]%10;
                c[i+j]%=10;
            }
            c[i+j-1]+=(a[i]-'0')*(b[i]-'0')%10;
            if(c[i+j-1]>=10)
            {
                c[i+j]+=c[i+j-1]%10;
                c[i+j-1]%=10;
            }
        }
    }
    for(int i=lena*lenb;i>=0;i--)
    {
        if(c[i]>0)
        {
            d=1;
        }
        if(d)
        {
            cout<<c[i];
        }
    }
    return 0;
}

样栗连输出都没有QAQ


by 0xC00000FD @ 2020-07-15 20:56:06

lei了lei了

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main() {
    char a[2005] = { 0 }, b[2005] = { 0 };
    int c[4005] = { 0 },lena, lenb;

    cin >> (a + 1) >> (b + 1);

    if (!strcmp(a + 1, "0") || !strcmp(a + 1, "0")) {
        return !putchar('0');
    }

    lena = strlen(a + 1);
    lenb = strlen(b + 1);

    for(int i = lena; i > 0; i --) {
        for(int j = lenb; j > 0; j --) {
            c[i + j - 1] += (a[i] - '0') * (b[j] - '0');
            if(c[i + j - 1] >= 10) {
                c[i + j - 2] += c[i + j - 1] / 10;
                c[i + j - 1] %= 10;
            }
        }
    }

    int len = lena + lenb - 1, start = 1;
    if (c[0]) start = 0;

    for (int i = start; i <= len; i ++)
        putchar(c[i] ^ 48);

    return 0;
}

by 0xC00000FD @ 2020-07-15 20:57:14

这种题目建议即使浪费一点时间也要写结构体, 为了之后需要大量使用高精度的题目的便利


by _SkyBlue @ 2020-08-10 18:22:48

@zhoukangyang orzky!!!


上一页 |