Advertisement
Sanlover

Untitled

Dec 2nd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int main() {
  7. fstream input("input.txt");
  8.  
  9. if (!input.is_open()) {
  10. cout << "file not found" << endl;
  11. return 0;
  12. }
  13.  
  14. priority_queue<int> values;
  15. int tmp, value;
  16. while (!input.eof()) {
  17. input >> tmp;
  18. values.push(tmp);
  19. }
  20. input.close();
  21.  
  22. const size_t iterations = values.size();
  23. vector<int> buffer;
  24. for (size_t i = 0; i < iterations; i++) {
  25. cout << values.top() << " ";
  26. buffer.push_back(values.top());
  27. values.pop();
  28. }
  29. for (auto &it : buffer) values.push(it);
  30. buffer.clear();
  31.  
  32. cout << endl;
  33. cout << endl;
  34. cout << "Enter the value, you want to change = ";
  35. cin >> tmp;
  36. cout << "Enter the value you want to assign = ";
  37. cin >> value;
  38.  
  39. for (size_t i = 0; i < iterations; i++) {
  40. buffer.push_back(values.top());
  41. values.pop();
  42. }
  43. for (auto &it : buffer) {
  44. if (it == tmp)
  45. values.push(value);
  46. else
  47. values.push(it);
  48. }
  49.  
  50. for (size_t i = 0; i < iterations; i++) {
  51. cout << values.top() << " ";
  52. buffer.push_back(values.top());
  53. values.pop();
  54. }
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement