Advertisement
Checosnake

Twitter Challenge

Jan 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <string>
  10. #include <bitset>
  11. #include <cstdio>
  12. #include <limits>
  13. #include <vector>
  14. #include <climits>
  15. #include <cstring>
  16. #include <cstdlib>
  17. #include <fstream>
  18. #include <numeric>
  19. #include <sstream>
  20. #include <iostream>
  21. #include <algorithm>
  22. #include <unordered_map>
  23.  
  24. using namespace std;
  25.  
  26. int main() {
  27.     //Initialize & Declare Variables As Needed
  28.     string input = " ";
  29.     bool inputover = false;
  30.     deque<char> str;
  31.     deque<char> cmd;
  32.    
  33.     //Cycle until no more input
  34.     while(!inputover)
  35.     {
  36.         //Get input
  37.         getline(cin,input);
  38.        
  39.         //Prepare for next input
  40.         cin.clear();
  41.        
  42.         //Check if end of input
  43.         if(input.empty())
  44.         {
  45.             break;  
  46.         }
  47.    
  48.         //-----------------------------------------------------------
  49.         //Start individual input code below here
  50.         //-----------------------------------------------------------
  51.        
  52.         //Iterate though String
  53.         while(input.length() > 0)
  54.         {
  55.             //Detect slash to indicate instruction
  56.             if(input[0]=='/')
  57.             {
  58.                 input.erase(input.begin());
  59.                 //Iterate through remaining string and split expression from Instruction
  60.                 while(input.length() > 0)
  61.                 {
  62.                     cmd.push_back(input[0]);
  63.                     input.erase(input.begin());
  64.                 }
  65.             }
  66.             else
  67.             {
  68.                 str.push_back(input[0]);
  69.                 input.erase(input.begin());
  70.             }
  71.         }
  72.        
  73.        
  74.         while(!cmd.empty())
  75.         {
  76.            
  77.             if(cmd.front() == 'R')
  78.             {
  79.                 stack<char> temp;
  80.                 while(!str.empty())
  81.                 {
  82.                     if(str.front() == '(')
  83.                     {
  84.                         temp.push(')');
  85.                     }
  86.                     else if(str.front() == ')')
  87.                     {
  88.                         temp.push('(');
  89.                     }
  90.                     else
  91.                     {
  92.                         temp.push(str.front());
  93.                     }
  94.                     str.pop_front();
  95.                 }
  96.                 while(!temp.empty())
  97.                 {
  98.                     str.push_back(temp.top());
  99.                     temp.pop();
  100.                 }
  101.                
  102.             }
  103.             if(cmd.front() =='S')
  104.             {
  105.                 if (str.[0]
  106.             }
  107.             cmd.pop_front();
  108.         }
  109.        
  110.         //Display Expression
  111.         //cout << "String" << endl;
  112.         for (int i = 0; i < str.size(); i++)
  113.         {
  114.             cout << str[i];
  115.         }
  116.         cout << endl;
  117.        
  118.         /*
  119.         //Display Instructions
  120.         cout << "Command" << endl;
  121.         for (int i = 0; i < cmd.size(); i++)
  122.         {
  123.             cout << cmd[i];
  124.         }
  125.         cout << endl;
  126.         */
  127.        
  128.        
  129.        
  130.         str.clear();
  131.         cmd.clear();
  132.     }
  133.    
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement