Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <list>
  5. #include <cmath>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int hashh(int N) {
  11. return N % 2671;
  12. }
  13.  
  14. vector <list <int>> hashtable(2671);
  15.  
  16. int main() {
  17. ifstream f("input.txt");
  18. ofstream f1("output.txt");
  19.  
  20. int a;
  21. f >> a;
  22.  
  23. while (a != 0) {
  24.  
  25. if (a > 0) {
  26. bool is_in = false;
  27.  
  28. int h;
  29. h = hashh(a);
  30.  
  31. for (auto iter = hashtable[h].begin(); iter != hashtable[h].end(); iter++) {
  32. if (*iter == a) {
  33. is_in = true;
  34. break;
  35. }
  36. }
  37.  
  38. if (!is_in) {
  39. hashtable[hashh(a)].push_back(a);
  40. }
  41. }
  42. else {
  43. int h;
  44. h = hashh(abs(a));
  45.  
  46. for (auto iter = hashtable[h].begin(); iter != hashtable[h].end(); iter++) {
  47. if (*iter == abs(a)) {
  48. hashtable[h].erase(iter);
  49. break;
  50. }
  51. }
  52. }
  53. f >> a;
  54. }
  55.  
  56. vector <int> vec;
  57.  
  58. for (int j = 0; j < hashtable.size(); j++) {
  59. for (auto iter = hashtable[j].begin(); iter != hashtable[j].end(); iter++) {
  60. vec.push_back(*iter);
  61. }
  62. }
  63.  
  64. sort(vec.begin(), vec.end());
  65.  
  66. for (auto iter = vec.begin(); iter != vec.end(); iter++) {
  67. f1 << *iter << ' ';
  68. }
  69.  
  70. f.close();
  71. f1.close();
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement