Advertisement
Guest User

Untitled

a guest
May 5th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <map>
  8. #include <list>
  9.  
  10. using namespace std;
  11. int a,b;
  12. bool ListCompare(int c){
  13. return ((c>a)&(c<b));
  14. }
  15.  
  16. typedef unsigned uint;
  17. typedef unsigned long ulong;
  18. typedef unsigned long long ull;
  19.  
  20. int main() {
  21. setlocale(LC_CTYPE,"rus");
  22. FILE *f1, *f2;
  23. map<string, int> book;
  24. //1
  25.  
  26. vector<int> my_vec(5);
  27. ofstream fout;
  28. fout.open("D:\\f1.txt");
  29. for(uint i = 0; i < my_vec.size(); i++) {
  30. fout << i << endl;
  31. }
  32. fout.close();
  33.  
  34. ifstream fin;
  35. fin.open("D:\\f1.txt");
  36. for(uint i = 0; i < my_vec.size(); i++) {
  37. fin >> my_vec[i];
  38. }
  39. fin.close();
  40.  
  41. cout << " 1 - По возрастанию_" <<endl;
  42. cout << " 2 - По убыванию_"<<endl;
  43. int mod;
  44. cin >> mod;
  45.  
  46. switch (mod) {
  47. case 1: sort(my_vec.begin(),my_vec.end() );
  48. case 2: {
  49. sort(my_vec.begin(), my_vec.end());
  50. reverse(my_vec.begin(), my_vec.end());
  51. }
  52. }
  53.  
  54. fout.open("D:\\f1.txt");
  55. for(uint i = 0; i < my_vec.size(); i++) {
  56. fout << my_vec[i] <<' ';
  57.  
  58. }
  59.  
  60. fout <<endl;
  61.  
  62. my_vec.clear();
  63. fout.close();
  64.  
  65.  
  66. //2
  67. FILE *f4;
  68. list <int> my_list;
  69. int n,j;
  70. string s1;
  71. ifstream fin_list;
  72.  
  73. fin_list.open("D:\\f4.txt");
  74. cout << "Назовите файл_" << endl;
  75. cin >> s1;
  76. ofstream fout_list(s1);
  77.  
  78. for (int j=0;j<5;j++){
  79. cin>>n;
  80. my_list.push_back(n);
  81. }
  82. fin_list.close("D:\\f4.txt");
  83. cout << "Введите 2 числа_" << endl;
  84. cin >> a >> b;
  85. my_list.remove_if(ListCompare);
  86. fout_list.open()
  87. for (list<int>::iterator I = my_list.begin(); I != my_list.end();I++){
  88. fout_list << *I <<endl;
  89. }
  90.  
  91.  
  92. }
  93. fout_list.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement