Created
March 19, 2020 08:12
-
-
Save joonas-yoon/7f1b10ff6254665de39b77ce4f99e255 to your computer and use it in GitHub Desktop.
alternative for STL - test/main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
// if you want to use STL, uncomment following includes: | |
// #include <vector> | |
// #include <algorithm> | |
// using namespace std; | |
// count "key" from array sized n | |
// if no key, print "NO" | |
int main() { | |
int n; | |
scanf("%d", &n); | |
vector<int> v(n); | |
for (int i = 0; i < v.size(); ++i) scanf("%d", &v[i]); | |
sort(v.begin(), v.end()); | |
for (int i = 0; i < v.size(); ++i) printf("%d ", v[i]); puts(""); | |
int key; | |
scanf("%d", &key); | |
if (binary_search(v.begin(), v.end(), key)) { | |
int equal_count = upper_bound(v.begin(), v.end(), key) - lower_bound(v.begin(), v.end(), key); | |
printf("%d\n", equal_count); | |
} | |
else { | |
puts("NO"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment