蒟蒻写的高精度最后一个点wa了

P1303 A*B Problem

w_god @ 2023-08-30 21:31:34


#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
char s1[N] , s2[N] , op[N];
int a[N] , b[N] , c[N];
void change(char *s , int num[])
{
    int len = strlen(s);
    for (int i = 0 ; i < len ; i++)
    {
        num[len - 1 - i] = s[i] - '0';
    }
}
void jian(int a[] , int b[] , int c[])
{
    int jie = 0;
    for (int i = 0 ; i < N - 1 ; i++)
    {
        if (jie)
        {
            c[i] = a[i] - b[i] - 1;
            jie = 0;
        }
        else
        {
            c[i] = a[i] - b[i];
        }
        if (c[i] < 0)
        {
            c[i] += 10; 
            jie = 1;
        }
    }
}
void print(int num[])
{
    int len = N - 1;
    while (len >= 1 && num[len] == 0)
    {
        len--;
    }
    for (int i = len ; i >= 0 ; i--)
    {
        printf("%d" , num[i]);
    }
}
bool xiao(char *s , char *t)
{
    int len1 = strlen(s);
    int len2 = strlen(t);
    if (len1 != len2)
    {
        return len1 < len2;
    }
    for (int i = 0 ; i < len1 ; i++)
    {
        if (s[i] != t[i])
        {
            return s[i] < t[i];
        }
    }
    return false;
}
int main()
{
    scanf("%s%s" , s1 , s2);
    change(s1 , a);
    change(s2 , b);
    for (int i = 0 ; s1[i] ; i++)
    {
        for (int j = 0 ; s2[j] ; j++)
        {
            c[i + j] += a[i] * b[j];
        }
    }
    for (int i = 0 ; i < N - 1 ; i++)
    {
        c[i + 1] += c[i] / 10;
        c[i] %= 10;
    }
    print(c);
}

by w_god @ 2023-08-30 21:32:55

bool类型的xiao函数可以不管,之前写代码忘删了qwq


by liuhaopeng666 @ 2023-08-30 21:34:31

@w_god

C数组是不是开小了啊,两数相乘数位最多为2n 的哦


by w_god @ 2023-08-30 21:36:51

@liuhaopeng666 蟹蟹大佬,改完后AC了,已关注qwq


|