我正在尝试使用C++ 库中的lower_bound和upper_bound函数algorithm来查找以下内容:
我写了以下代码:
#include <iostream>
#include <algorithm>
int main() {
using namespace std;
int numElems;
cin >> numElems;
int ar[numElems];
for (int i = 0; i < numElems; ++i)
cin >> ar[i];
stable_sort(ar,ar+numElems);
cout << "Input number X to find the largest number samller than or equal to X\n";
int X;
cin >> X;
int *iter = lower_bound(ar,ar+numElems,X);
if (iter == ar+numElems)
cout << "Sorry, no …Run Code Online (Sandbox Code Playgroud) 我使用声明而不是使用显式std::方式来使用标准库对象.我得到的是否有使用任何性能提升了这个问题使用声明 S,使用声明 S和直接使用的名字从标准库.
例如:
要打印出"Hello world",我们可以写出以下方法:
通过使用裸露的std::方式:
std::cout << "Hello world";
通过使用声明:
using std::cout; cout << "Hello world";
通过使用声明:
using namespace std; cout << "Hello world";
那么,上述哪种方法具有最佳性能?更有效率?