Advertisement
sve_vash

Untitled

Jul 3rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <list>
  5. #include <bits/stdc++.h>
  6.  
  7. #define SIZE 13109;
  8.  
  9. using namespace std;
  10.  
  11. int hashf(int n) {
  12. int i = 0;
  13. for(; n > 0; n /= 10)
  14. i = i * 10 + (n % 10);
  15. return i % SIZE;
  16. }
  17.  
  18. int main() {
  19. vector <list <int>> hasht;
  20. vector <int> kkk;
  21. hasht.resize(13109);
  22. ifstream inp("input.txt");
  23. ofstream outp("output.txt");
  24.  
  25. list<int>::iterator iter;
  26. int a;
  27. while (true) {
  28. inp >> a;
  29. if (a == 0) break;
  30. else if (a > 0) {
  31. bool exist = false;
  32. for (auto v : hasht[hashf(a)]) {
  33. if (v == a) {
  34. exist = true;
  35. break;
  36. }
  37. }
  38. if (!exist) {
  39. hasht[hashf(a)].push_back(a);
  40. }
  41. }
  42. else {
  43. for (iter = hasht[hashf(-a)].begin(); iter != hasht[hashf(-a)].end(); ++iter) {
  44. if (*iter == -a) {
  45. hasht[hashf(-a)].remove(*iter);
  46. break;
  47. }
  48. }
  49. }
  50. }
  51.  
  52. for (int i = 0; i < hasht.size(); ++i){
  53. if (hasht[i].empty()) continue;
  54. for (auto v : hasht[i])
  55. kkk.push_back(v);
  56. }
  57.  
  58. sort(kkk.begin(), kkk.end());
  59.  
  60. for (auto j = kkk.begin(); j != kkk.end(); ++j)
  61. outp << *j << ' ';
  62.  
  63. inp.close();
  64. outp.close();
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement