C++语法:求vector中的最大值及其位置
生活随笔
收集整理的這篇文章主要介紹了
C++语法:求vector中的最大值及其位置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
#include <iostream> #include <vector> #include <algorithm> using namespace std;int main(){vector<int> a = { 2,4,6,7,1,0,8,9,6,3,2 };auto maxPosition = max_element(a.begin(), a.end());cout << *maxPosition << " at the postion of " << maxPosition - a.begin() <<endl;//cout << a[maxPosition - a.begin()] << " at the postion of " << distance(a.begin(), maxPosition) << endl;system("pause");return 0; }效果:
轉載地址:
https://blog.csdn.net/qxconverse/article/details/67638545?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
總結
以上是生活随笔為你收集整理的C++语法:求vector中的最大值及其位置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++语法:vector的使用
- 下一篇: C++中的sort函数对二维数组排序是按