第一个测试点不过但本地正常输出

P1303 A*B Problem

R5yEr4Z @ 2024-12-16 22:38:58

代码如下

#include <stdio.h>
#include <string.h>
void mult_Accurate_Highly(char str1[], char str2[])
  {  
  int arr1[4020] = {0}, arr2[4020] = {0}, arr3[4020] = {0};
  int len1 = strlen(str1), len2 = strlen(str2);

  for (int i = 0; i < len1; i++){arr1[len1 - i - 1] = str1[i] - '0';}
  for (int i = 0; i < len2; i++){arr2[len2 - i - 1] = str2[i] - '0';}

  for (int i = 0; i < len2; i++)
  {
    for (int j = 0; j < len1; j++)
    {
      arr3[j + i] += arr1[j] * arr2[i];
      if (arr3[j + i] > 9)
      {
        arr3[j + i + 1] += arr3[ j + i] / 10;
        arr3[j + i] %= 10;
      }

    }

  }
  int index = 0;
  int len = len1 + len2;
  for (int i = len - 1; i >= 0; i--)
  {
    if (arr3[i] != 0)
    {
      index = i;
      break;
    }

  }
  for (int i = index; i >= 0; i--)
  {
    printf("%d", arr3[i]);
  }

  for (int i = index; i >= 0; i--)
  {
    str2[index - i] = arr3[i] + '0';
  }
}

int main(void)
{
  char str1[4020], str2[4020];
  fgets(str1, sizeof(str1), stdin);
  fgets(str2, sizeof(str2), stdin);
  str1[strlen(str1) - 1] = 0; // 去除换行符
  str2[strlen(str2) - 1] = 0;
  mult_Accurate_Highly(str1, str2);
  //for (int i = 0; i < strlen(str2); i++)
  //{
  //  printf("%d", str2[i] - '0');
  //}

}

by QinCode @ 2024-12-31 16:21:10

哈哈,我也遇到了,其实第一个测试点是乘以0


|