gpt4 book ai didi

c++ - 错误: invalid operands of types 'int' and '' to binary 'operator<='

转载 作者:行者123 更新时间:2023-12-03 08:24:24 26 4
gpt4 key购买 nike

我的代码:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;
while( t-- ) {
int n, x = 0;
cin >> n;
if(n % 2 == 0)
cout << n/2 <<" "<< n/2 << endl;
else
int min = INT_MAX;
for(int i = 1; i*i <= n; i++) {
if(( n-i) % i == 0) {
int d = (n-i) / i;
if(d <= min) {
min = d;
x = i;
}
}
}
cout << x <<" "<< n-x <<endl;
}
// your code goes here
return 0;
}
该代码给出了一些我无法处理的典型错误。
请任何人帮我修复它。

C:\Users\HP\Desktop\Code\hello.cpp:21:20: error: invalid operands of types 'int'
and '' to binary 'operator<='21 | if(d<=min)| ~^~~~~

最佳答案

问题是您错过了{}情况下的else:

else
int min=INT_MAX;
for(int i=1;i*i<=n;i++)
因此, int min的范围仅限于定义它的单行。在 if(d<=min)中,编译器会改为看到 std::min()函数模板(这是因为您不建议使用 using namespace std;)。

关于c++ - 错误: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<=' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65419045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com