Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1 9 15 16 19
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct det
- {
- int nomDet;
- int post;
- int kol;
- int month;
- int year;
- };
- struct povt
- {
- int NomDet;
- int Post;
- int Kol;
- int Month;
- int Year;
- };
- void formBin(ifstream &f,ofstream &g)
- {
- det a;
- while (f.peek()!=EOF)
- {
- f >> a.nomDet >> a.post >> a.kol >> a.month >> a.year;
- g.write((char *)&a,sizeof det);
- cout<<' '<< a.nomDet <<' '<< a.post << ' ' << a.kol << ' ' << a.month << ' ' << a.year<<endl;
- }
- }
- void rezult(ifstream &f, ofstream &g)
- {
- int *n = new int[100];
- for (int i = 0; i < 100; i++)
- {
- n[i] = 0;
- }
- det a;
- povt b;
- //f.read((char *)&a, sizeof det);
- //f.read((char *)&b, sizeof povt);
- for (int i = 0; f.peek() != EOF; i++)
- {
- f.read((char *)&a, sizeof det);
- n[i] = a.nomDet;
- }
- for (int i = 1;f.eof();i++)
- {
- f.read((char *)&a, sizeof det);
- if (n[0] != n[1])
- {
- g.write((char*)&a, sizeof det);
- }
- else if (n[i - 1] != n[i] && n[i] != n[i + 1])
- {
- g.write((char*)&a, sizeof det);
- }
- }
- }
- void showBin(ifstream &f)
- {
- det a;
- while (f.peek() != EOF)
- {
- f.read((char *)&a, sizeof povt);
- cout << a.nomDet << ' ' << a.post << ' ' << a.kol << ' ' << a.month << ' ' << a.year << endl;
- }
- }
- int main()
- {
- povt b;
- det a;
- ifstream in("input.txt");
- ofstream out("output.bin",ios::binary);
- formBin(in,out);
- in.close();
- out.close();
- cout << endl;
- ifstream in1("output.bin",ios::binary);
- ofstream out1("outRez.bin", ios::binary);
- rezult(in1, out1);
- out1.close();
- in1.close();
- cout << endl;
- ifstream in3("outRez.bin", ios::binary);
- showBin(in3);
- in3.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement