我的代码:
#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/