abubaca

Untitled

Feb 18th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.     if (argc != 2)
  9.     {
  10.         cout << "Please enter file to analysis as a command line argument" << endl;
  11.         cin.get();
  12.         return 0;
  13.     }
  14.     ifstream data(argv[1]);
  15.     if (!data.is_open())
  16.     {
  17.         cout << "File not found!" << endl;
  18.         cin.get();
  19.         return 0;
  20.     }
  21.     ofstream out("out.txt");
  22.     if (!out.is_open())
  23.     {
  24.         cout << "Could not create/edit output file" << endl;
  25.         cin.get();
  26.         return 0;
  27.     }
  28.     int flag = 0;
  29.     char temp;
  30.     while (!data.eof())
  31.     {
  32.         data >> temp;
  33.         switch (flag)
  34.         {
  35.         case 0:
  36.             if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
  37.                 out << temp;
  38.             else
  39.                 if (temp == '-')
  40.                     flag = 1;
  41.                 else
  42.                     if (temp >= '0' && temp <='9')
  43.                     {
  44.                         out << temp;
  45.                         flag = 2;
  46.                     }
  47.             break;
  48.         case 1:
  49.             if (temp >= '0' && temp <= '9')
  50.             {
  51.                 flag = 2;
  52.                 out << '-' << temp;
  53.             }
  54.             else
  55.             {
  56.                 flag = 0;
  57.                 if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
  58.                     out << temp;
  59.             }
  60.             break;
  61.         case 2:
  62.             if (temp >= '0' && temp <= '9')
  63.                 out << temp;
  64.             else
  65.             {
  66.                 flag = 0;
  67.                 if ((temp == '(') || (temp == ')') || (temp == '{') || (temp == '}') || (temp == '[') || (temp == ']'))
  68.                     out << temp;
  69.             }
  70.             break;
  71.         }
  72.     }
  73.     cout << "Jobe done" << endl;
  74.     cin.get();
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment