C ++ STLでlower_bound()関数を設定します
C ++でsetlower_bound()関数を設定すると、STLは、パラメーターで渡されたkに相当するコンテナー内の要素を指すイテレーターを返します。セットコンテナにkが存在しない場合、関数はkより少し大きい直前の要素を指すイテレータを返します。
アルゴリズム
Begin Initialize an empty set container s. Initializing a set container as inetrator. Insert some elements in s set container. Call function to find the lower bound value of a given key, which is passed to iter set container. Print the lower bound value of the given key. End.
サンプルコード
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
set<int> s; //Declaring an empty set container
set<int>::iterator iter; //Declaring a set container as iterator which will point to the lower bound value
s.insert(7); //inserting elements in the set container s
s.insert(6);
s.insert(1);
s.insert(4);
s.insert(2);
s.insert(9);
s.insert(10);
iter = s.lower_bound(4); //passing a key by parameter to find its lower bound
cout <<"The lower bound of 4 is: "<< *iter << " "<<endl; //printing the lowerbound value
iter = s.lower_bound(5);
cout <<"The lower bound of 5 is: " <<*iter << " "<<endl;
iter = s.lower_bound(30);
cout <<"The lower bound of 30 is: " <<*iter << " "<<endl;
return 0;
} 出力
The lower bound of 4 is: 4 The lower bound of 5 is: 6 The lower bound of 30 is: 7
-
C++STLの関数を無効にします
ネゲート関数は、値の符号を変更するように、指定された値をネゲートするために使用されます。負の値を正に、またはその逆に変更します。 関数プロトタイプ: function transform(a_begin, a_end, a1_begin, negate()): a_begin = lower bound of the array. a_end = upper bound of the array. a1_end = Lower bound of the second modified array. &n
-
C ++ STLのatan2()関数
atan2()関数は、yとxに関する座標の正接逆関数を返します。ここで、yとxは、それぞれy座標とx座標の値です。これはC++STLに組み込まれている関数です。 atan2()関数の構文は次のとおりです。 atan2(dataType var1, dataType var2) 構文からわかるように、関数atan2()は、データ型floatの2つのパラメーターvar1とvar2、それぞれyとxポイントであるdoubleまたはlongdoubleを受け入れます。 atan2()によって返される値は、-piからpiの範囲であり、(x、y)と正のx軸の間の角度です。 C ++でatan2()を