【发布时间】:2020-04-12 10:37:51
【问题描述】:
我有两个长整数的向量“a”和“b”,我希望将“a”和“b”各自元素的差异放入向量“c”中。但我不希望这些差异低于 0。
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<long long int> a={360757931684,484141693549};
vector<long long int> b={186119101678,675563431537};
vector<long long int> c;
vector<long long int> d;
for (int i=0; i<2; i++){
// c.push_back(max(0,a[i]-b[i]));
c.push_back(max(0ll,a[i]-b[i]));
//I need to use "0ll" to make this work, Because the commented line above doesn't work
}
for (int i=0; i<2; i++){
if (a[i]-b[i]>0)
//Here this works fine even without "0ll"
d.push_back(a[i]-b[i]);
else
d.push_back(0);
}
return 0;
}
在使用std::max 函数时,我必须使用0ll,但在使用> 运算符时,仅使用0 就足够了。为什么?
【问题讨论】: