Advertisement
AndreyIshmanov

Untitled

Mar 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //1 9 15 16 19
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <fstream>
  5. using namespace std;
  6. struct det
  7. {
  8. int nomDet;
  9. int post;
  10. int kol;
  11. int month;
  12. int year;
  13. };
  14. struct povt
  15. {
  16. int NomDet;
  17. int Post;
  18. int Kol;
  19. int Month;
  20. int Year;
  21. };
  22. void formBin(ifstream &f,ofstream &g)
  23. {
  24. det a;
  25. while (f.peek()!=EOF)
  26. {
  27. f >> a.nomDet >> a.post >> a.kol >> a.month >> a.year;
  28. g.write((char *)&a,sizeof det);
  29. cout<<' '<< a.nomDet <<' '<< a.post << ' ' << a.kol << ' ' << a.month << ' ' << a.year<<endl;
  30. }
  31. }
  32. void rezult(ifstream &f, ofstream &g)
  33. {
  34. int *n = new int[100];
  35. for (int i = 0; i < 100; i++)
  36. {
  37. n[i] = 0;
  38. }
  39. det a;
  40. povt b;
  41. //f.read((char *)&a, sizeof det);
  42. //f.read((char *)&b, sizeof povt);
  43. for (int i = 0; f.peek() != EOF; i++)
  44. {
  45. f.read((char *)&a, sizeof det);
  46. n[i] = a.nomDet;
  47.  
  48. }
  49.  
  50. for (int i = 1;f.eof();i++)
  51. {
  52. f.read((char *)&a, sizeof det);
  53. if (n[0] != n[1])
  54. {
  55. g.write((char*)&a, sizeof det);
  56. }
  57. else if (n[i - 1] != n[i] && n[i] != n[i + 1])
  58. {
  59. g.write((char*)&a, sizeof det);
  60. }
  61. }
  62. }
  63. void showBin(ifstream &f)
  64. {
  65. det a;
  66. while (f.peek() != EOF)
  67. {
  68. f.read((char *)&a, sizeof povt);
  69. cout << a.nomDet << ' ' << a.post << ' ' << a.kol << ' ' << a.month << ' ' << a.year << endl;
  70. }
  71. }
  72. int main()
  73. {
  74. povt b;
  75. det a;
  76. ifstream in("input.txt");
  77. ofstream out("output.bin",ios::binary);
  78. formBin(in,out);
  79. in.close();
  80. out.close();
  81. cout << endl;
  82. ifstream in1("output.bin",ios::binary);
  83. ofstream out1("outRez.bin", ios::binary);
  84. rezult(in1, out1);
  85. out1.close();
  86. in1.close();
  87. cout << endl;
  88. ifstream in3("outRez.bin", ios::binary);
  89. showBin(in3);
  90. in3.close();
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement