Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. #define INPUT "input.txt"
  5. #define OUTPUT "output.txt"
  6.  
  7. using namespace std;
  8.  
  9. struct Symbol
  10. {
  11.     char ch;
  12.     Symbol* next = NULL;
  13. };
  14.  
  15. bool check(Symbol* firstSymbol)
  16. {
  17.     bool dlt = false;
  18.     Symbol* nowSymbol = firstSymbol, * buf;
  19.     while (nowSymbol->next != NULL)
  20.     {
  21.         if (nowSymbol->next->ch == firstSymbol->ch)
  22.         {
  23.             dlt = true;
  24.             buf = nowSymbol->next->next;
  25.             delete(nowSymbol->next);
  26.             nowSymbol->next = buf;
  27.         }
  28.         else
  29.             nowSymbol = nowSymbol->next;
  30.     }
  31.     return dlt;
  32. }
  33.  
  34.  
  35. void main()
  36. {
  37.     char ch;
  38.     bool empty = true;
  39.  
  40.     fstream file;
  41.     file.open(INPUT);
  42.  
  43.     if (file.is_open())
  44.     {
  45.         Symbol* firstSymbol = new Symbol, * nowSymbol = firstSymbol, *buf;
  46.         while (!file.eof())
  47.         {
  48.             ch = file.get();
  49.             if ((ch != ' ') && (ch != EOF))
  50.             {
  51.                 cout << ch << "\n";
  52.                 nowSymbol->next = new Symbol;
  53.                 nowSymbol = nowSymbol->next;
  54.                 nowSymbol->ch = ch;
  55.                 empty = false;
  56.             }
  57.         }
  58.         if (empty != true)
  59.         {
  60.             cout << "_____________ \n";
  61.  
  62.             file.close();
  63.  
  64.             file.open(OUTPUT, ios_base::out | ios_base::trunc);
  65.             if (file.is_open())
  66.             {
  67.                 nowSymbol = firstSymbol;
  68.                 while (nowSymbol->next != NULL)
  69.                 {
  70.                     if (check(nowSymbol->next))
  71.                     {
  72.                         buf = nowSymbol->next->next;
  73.                         delete(nowSymbol->next);
  74.                         nowSymbol->next = buf;
  75.                     }
  76.                     else
  77.                     {
  78.                         cout << nowSymbol->next->ch << "\n";
  79.                         file << nowSymbol->next->ch << " ";
  80.                         nowSymbol = nowSymbol->next;
  81.                     }
  82.                 }
  83.                 file.close();
  84.             }
  85.             else
  86.             {
  87.                 cout << "Output file not found!\n";
  88.             }
  89.         }
  90.         else
  91.             cout << "File is empty!\n";
  92.     }
  93.     else {
  94.  
  95.         cout << "Input file not found!\n";
  96.  
  97.     }
  98.     cin >> ch;
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement