Created
October 27, 2018 14:43
-
-
Save Caellian/0670b86ca26ef359b3e1e6a222fa0787 to your computer and use it in GitHub Desktop.
NKD
This file contains hidden or 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 <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| std::vector<std::string> nkd; | |
| int k, n; | |
| int main() | |
| { | |
| std::cin >> k >> n; | |
| for(int i = 0; i < n; i++) { | |
| std::string in; | |
| std::cin >> in; | |
| if (std::find(nkd.begin(), nkd.end(), in) != nkd.end()) { | |
| nkd.erase(std::find(nkd.begin(), nkd.end(), in)); | |
| nkd.push_back(in); | |
| } else { | |
| if (nkd.size() >= k) { | |
| nkd.erase(nkd.end()); | |
| nkd.push_back(in); | |
| } else { | |
| nkd.push_back(in); | |
| } | |
| } | |
| } | |
| std::cout << std::endl; | |
| for(int i = k - 1; i >= 0; i--) { | |
| std::cout << nkd[i] << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment