Advertisement
Guest User

Untitled

a guest
May 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <list>
  4. using namespace std;
  5.  
  6. #define SIZE 1
  7.  
  8. struct dane
  9. {
  10. char *from = new char[16];
  11. char *to = new char[16];
  12. int kwota = 0;
  13.  
  14. void setKwota(int kwota)
  15. {
  16. this->kwota = kwota + this->kwota;
  17. }
  18.  
  19. int getKwota()
  20. {
  21. return kwota;
  22. }
  23.  
  24. char* getFrom()
  25. {
  26. return from;
  27. }
  28. char* getTo()
  29. {
  30. return to;
  31. }
  32. };
  33.  
  34. int xd(char *from)
  35. {
  36. int sum1 = 0;
  37. for (int i = 0; i < strlen(from); i++) sum1 = sum1 + from[i];
  38.  
  39. return sum1;
  40. }
  41.  
  42.  
  43. int hashing(char *ppl1, char *ppl2)
  44. {
  45. int sum1 = 0;
  46. int sum2 = 0;
  47. for (int i = 0; i < strlen(ppl1); i++) sum1 = sum1 + ppl1[i]*i;
  48. for (int i = 0; i < strlen(ppl2); i++) sum2 = sum2 + ppl2[i]*(strlen(ppl2)-i);
  49.  
  50. return (sum1 + sum2) % SIZE;
  51. }
  52.  
  53. int main()
  54. {
  55. char opt;
  56. char *from = new char[16];
  57. char *to = new char[16];
  58. int kwota, index;
  59. list<dane> arr[SIZE];
  60.  
  61. while (cin >> opt)
  62. {
  63.  
  64. if (opt == '+')
  65. {
  66. int spr = 1;
  67. cin >> from >> to;
  68. index = hashing(from, to);
  69. cin >> kwota;
  70.  
  71. list<dane> ::iterator i;
  72. for (i = arr[index].begin(); i != arr[index].end(); ++i)
  73. {
  74. if (i->getFrom() == from && i->getTo() == to)
  75. {
  76. cout << "RECHA TO CHUJ" << endl;
  77. i->setKwota(kwota);
  78. spr = 0;
  79. break;
  80. }
  81. }
  82.  
  83. if (spr == 1)
  84. {
  85. dane ar;
  86. ar.from = from;
  87. ar.to = to;
  88. ar.kwota = kwota;
  89. arr[index].push_back(ar);
  90. }
  91.  
  92.  
  93. }
  94. else if (opt == '?')
  95. {
  96. int spr = 1;
  97. cin >> from >> to;
  98. index = hashing(from, to);
  99.  
  100. list<dane> ::iterator i;
  101. for (i = arr[index].begin(); i != arr[index].end(); ++i)
  102. {
  103. if (i->getFrom() == from && i->getTo() == to)
  104. {
  105. cout << i->getKwota() << " " << endl <<
  106. from << " " << i->getFrom() << endl <<
  107. to << " " << i->getTo() << endl;
  108. spr = 0;
  109. break;
  110. }
  111. }
  112. if (spr == 1) cout << 0 << endl;
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement