Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <list>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- int hashh(int N) {
- return N % 2671;
- }
- vector <list <int>> hashtable(2671);
- int main() {
- ifstream f("input.txt");
- ofstream f1("output.txt");
- int a;
- f >> a;
- while (a != 0) {
- if (a > 0) {
- bool is_in = false;
- int h;
- h = hashh(a);
- for (auto iter = hashtable[h].begin(); iter != hashtable[h].end(); iter++) {
- if (*iter == a) {
- is_in = true;
- break;
- }
- }
- if (!is_in) {
- hashtable[hashh(a)].push_back(a);
- }
- }
- else {
- int h;
- h = hashh(abs(a));
- for (auto iter = hashtable[h].begin(); iter != hashtable[h].end(); iter++) {
- if (*iter == abs(a)) {
- hashtable[h].erase(iter);
- break;
- }
- }
- }
- f >> a;
- }
- vector <int> vec;
- for (int j = 0; j < hashtable.size(); j++) {
- for (auto iter = hashtable[j].begin(); iter != hashtable[j].end(); iter++) {
- vec.push_back(*iter);
- }
- }
- sort(vec.begin(), vec.end());
- for (auto iter = vec.begin(); iter != vec.end(); iter++) {
- f1 << *iter << ' ';
- }
- f.close();
- f1.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement