ソースを参照

STL 顺序查找find

zj 5 年 前
コミット
cd01835fc8
1 ファイル変更17 行追加0 行削除
  1. 17 0
      C1.cpp

+ 17 - 0
C1.cpp

@@ -0,0 +1,17 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    vector<int> v(10);
+    for (size_t i = 0; i < v.size(); i++)cin >> v[i];
+    int k;
+    cin >> k;
+    vector<int>::iterator it = find(v.begin(), v.end(), k);
+    if (it == v.end()) {
+        cout << "Not exist!" << endl;
+    } else {
+        cout << it - v.begin() << endl;
+    }
+    return 0;
+}