Advertisement
SenyaSych

Untitled

Mar 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <conio.h>
  3. #include <iomanip>
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <string>
  8. #include <Windows.h>
  9. #include <math.h>
  10. #include <fstream>
  11.  
  12. using namespace std;
  13.  
  14. ifstream fin;
  15. ofstream fout;
  16.  
  17.  
  18.  
  19. struct rec {
  20.     string marka;
  21.     string nomer;
  22.     string fio;
  23. };
  24.  
  25. struct sfio {
  26.     string fio;
  27.     sfio *next;
  28. };
  29.  
  30. struct spis {
  31.         string marka;
  32.         sfio *first;
  33.         sfio *last;
  34.         spis *next;
  35. };
  36.  
  37.  
  38. int main() {
  39.         setlocale(LC_ALL,"RUSSIAN");
  40.  
  41.         spis *first = NULL;
  42.         spis *current = NULL;
  43.         spis *last = NULL;
  44.         sfio  *rfio = NULL;
  45.  
  46.         fin.open("in.txt");
  47.  
  48.         while (!fin.eof()){
  49.  
  50.            rec *p = new rec;
  51.  
  52.             fin >>  p->marka;
  53.             fin >>  p->nomer;
  54.             fin >>  p->fio;
  55.  
  56.             current = first;
  57.             while(current)
  58.                 {
  59.                     if (current->marka == p->marka) {
  60.                         break;
  61.                     }
  62.                     last = current;
  63.                     current = current->next;
  64.  
  65.                 }
  66.  
  67.                if (!first) {
  68.                 current = new spis;
  69.                 current->marka = p->marka;
  70.                 current->first = NULL;
  71.                 first = current;
  72.             } else if (last && !current) {
  73.                 current = new spis;
  74.                 current->marka = p->marka;
  75.                 current->first = NULL;
  76.                 last->next = current;
  77.             }
  78.  
  79.             rfio = new sfio;
  80.             rfio->fio = p->fio;
  81.               if (!current->first){
  82.                     current->first = rfio;
  83.                     current->last = rfio;
  84.  
  85.               }
  86.               else {
  87.                 current->last->next = rfio;
  88.                 current->last = rfio;
  89.               }
  90.  
  91.         }
  92.           fin.close();
  93.           fout.open("out.txt");
  94.  
  95.         // печатаем список
  96.         current = first;
  97.         while (current)
  98.         {
  99.  
  100.                 fout << current->marka<<endl;
  101.                 rfio = current->first;
  102.  
  103.                 while(rfio) {
  104.                     fout << "   "<< rfio->fio<<endl;
  105.                     rfio = rfio->next;
  106.                 }
  107.  
  108.                 current = current->next;
  109.         }
  110.  
  111.     fout.clear();
  112.  
  113.         system ("pause");
  114.  
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement