Advertisement
Sanlover

Untitled

Dec 2nd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 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. 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. for (size_t i = 0; i < iterations; i++) {
  24. tmp = values.front();
  25. cout << tmp << " ";
  26. values.pop();
  27. values.push(tmp);
  28. }
  29.  
  30. cout << endl;
  31. cout << endl;
  32. cout << "Enter the value, you want to change = ";
  33. cin >> tmp;
  34. cout << "Enter the value you want to assign = ";
  35. cin >> value;
  36.  
  37. for (size_t i = 0; i < iterations; i++) {
  38. int reassign = values.front();
  39. values.pop();
  40. if (reassign == tmp)
  41. values.push(value);
  42. else
  43. values.push(reassign);
  44. }
  45. cout << endl;
  46. for (size_t i = 0; i < iterations; i++) {
  47. tmp = values.front();
  48. cout << tmp << " ";
  49. values.pop();
  50. values.push(tmp);
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement