1

我的操作系统:Windows 64 位

在 codeblocks 下:当我转到 Settings -> Compiler -> The selected compiler is "GNU GCC Compiler"

但是,在选项卡工具链可执行文件下

我看到以下信息:

编译器的安装目录:C:\Program Files (x86)\CodeBlocks\MinGW

C 编译器:mingw32-gcc.exe

C++ 编译器:mingw32-g++.exe

我正在尝试运行以下 C++ 程序:

#include<iostream>
#include<math.h>
using namespace std;
int find_size(int a,int b)
{
    int lena=0;
    int lenb=0;
    while(a>1)
    {
        lena++;
        a/=10;
    }
     while(b>1)
    {
        lenb++;
        b/=10;
    }
    if(lena%2!=0)
        lena+=1;
    if(lenb%2!=0)
        lenb+=1;
    return (lena>lenb?lena:lenb);
}
int karatsuba (int x , int y)
{
    if(x<=10 && y<=10)
        return x*y;
    int n=find_size(x,y);
    int p1 = pow(10,n/2);
    int p2 = pow (10,n);
    int a = x/p1;
    int b = x%p1;
    int c = y/p1;
    int d = y%p1;
    int pdt = p2*karatsuba(a,c)+p1*(karatsuba(a,d)+karatsuba(b,c))+karatsuba(b,d);
    return pdt;
}
int main()
{
    int x,y;
    cout<<"Enter the numbers"<<endl;
    cin>>x>>y;
    int ans=karatsuba(x,y);
    cout<<"\n Product : "<<ans<<endl;
    return 0;
}

相同的代码在在线编译器上运行时,给了我正确的输出。但是,代码块给了我不同的输出。我的编译器可能有什么问题?我的本地 Visual Studio 代码也有同样的问题。它给出了相同的错误输出。

示例:输入,x =2023,y=3003

正确答案(以及在线编译器的输出):6075069

但我的代码块和 VSC 的输出:6132081

我不知道我的代码块、VSC 或我的编译器出了什么问题。多年来我一直在使用相同的代码块,但从未遇到过这样的问题。

我可以提供的一个信息是几周前我安装了 MinGW,这会导致我的编译器设置出现问题吗?

有人可以帮我解决这个问题吗?

4

0 回答 0