Explorar o código

STL 顺序查找find

zj %!s(int64=5) %!d(string=hai) anos
pai
achega
cd01835fc8
Modificáronse 1 ficheiros con 17 adicións e 0 borrados
  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;
+}