Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. bool sortVector(double a, double b)
  8. {
  9. if (a >= 2 || b >= 2)
  10. {
  11. if (a > b) return true;
  12. else return false;
  13. }
  14. else
  15. {
  16. if (a > b)
  17. return false;
  18. else return true;
  19. }
  20. }
  21.  
  22. void show_vector(vector <double> a)
  23. {
  24. for (auto &i:a)
  25. {
  26. cout << i << " ";
  27. }
  28. cout << endl <<endl;
  29. }
  30. bool delVector(double a)
  31. {
  32. if (a > 1.5&&a < 3)
  33. {
  34. return true;
  35. }
  36. else return false;
  37. }
  38.  
  39.  
  40. int main(void)
  41. {
  42. setlocale(0, "rus");
  43. ifstream fin("in.txt");
  44. double buf;
  45. vector <double> Real;
  46. vector <double> delReal;
  47. while (!fin.eof())
  48. {
  49. fin >> buf;
  50. Real.push_back(buf);
  51. }
  52. cout << "До сортировки: " << endl;
  53. show_vector(Real);
  54. sort(Real.begin(), Real.end(), sortVector);
  55. cout << "После: " << endl;
  56. show_vector(Real);
  57. delReal.resize(Real.size());
  58. auto it=copy_if(Real.begin(), Real.end(), delReal.begin(), delVector);
  59. delReal.resize(distance(delReal.begin(), it));
  60. Real.erase(remove_if(Real.begin(), Real.end(),delVector), Real.end());
  61. cout << "После удаления :" << endl;
  62. show_vector(Real);
  63. cout << "Новый вектор: " << endl;
  64. show_vector(delReal);
  65. delReal.clear();
  66. Real.clear();
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement