All pastes #937729 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-11 04:23 UTC
rendered paste body
                                                                     

                                                                     

                                                                     

                                             

#include<iostream>

#include <cstdlib>

#include <string>



using namespace std;



int intconverter(string input, int position) {        

        char temp = input[position]; atoi(&temp);

        temp = temp - 48;

        return temp;

    };



string LSX(string input, int x) {

    int g = input.size();

    for (int i=0; i<=(g-x); i++) {

    input[i] = input[i+x];

    };

    for (int i=(g-x); i<g; i++) {

    input[i] ='#';

    }; 

    return input;

};



string RSX(string input, int x) {

    int g = input.size();

    for (int i=g; i>=x; i--) {

    input[i] = input[i-x];

    };

    for (int i=0; i<x; i++) {

    input[i] ='#';

    }; 

    return input;

};



string LCX(string input, int x) {

          string str1;

          str1.assign(input, 0, x);

          //cout << str1;

          input.erase(0 , x );

          input.append(str1);

          return input;

};



string RCX(string input, int x) {

          //cout<<"\n"<<"RC -"<<x<<": "<<input;

          string str1;

          str1.assign(input, input.size() - x , x); 

          input.erase(input.size() - x , x );

          str1.append(input);

          return str1;

};



string MCSLXD(string input, int s, int l, int x, char h) {

       string str1;

       str1.assign(input, s-1, l);

       if (h=='R') { str1 = RCX(str1,x); };

       if (h=='L') { str1 = LCX(str1,x); };

       input.replace(s-1,l,str1);

       return input; 

       

};



string REVSL(string input, int s, int l) {

    string temp;

    for (int i=0; i<l; i++) {

        temp[i] = input[s-1+i];

    };   

    for (int i=0; i<l; i++) {

        input[s-1+i] = temp[l-1-i];

    };

    return input;

}



int main ()

{

for (int loopy=1; loopy<=6; loopy++) {

     string input, query, command;

     int position;

     cout << ">";

     cin>>query;

     

     //Finding t3h input

     int m = query.find_last_of('/');

     input.assign(query, m+1, query.size());

     cout<<"INPUT:"<<input;

     int x = 3;

     int length = input.size();

     

     //Parsing

     //I. Get Command All By Its Lonesome

     //II. Process It!

     if (query.find("/",0) == -1) cout << "Invalid Statement"<<"\n";

     //Part A -get the command

     while (query.find("/",0) != -1) {

     m = query.find_first_of('/');

     command.clear();

     command.assign(query,0,m);

     int size = command.size();

     

     query.erase(0,m+1);



     if (command[0] == 'R' && command[1] == 'C') { 

        int holder = intconverter(command, 3);

        input = RCX(input, holder);

        cout << "rc  : "<<input<<"\n"; 

     };

     

     if (command[0] == 'L' && command[1] == 'C') { 

        int holder = intconverter(command, 3);

        input = LCX(input, holder);

        cout << "lc  : "<<input<<"\n"; 

     };

     

     if (command[0] == 'L' && command[1] == 'S') { 

        int holder = intconverter(command, 3);

        input = LSX(input, holder);

        cout << "ls  : "<<input<<"\n"; 

     };

     

     if (command[0] == 'R' && command[1] == 'S') { 

        int holder = intconverter(command, 3);

        input = RSX(input, holder);

        cout << "rs  : "<<input<<"\n"; 

     };

     

     if (command[0] == 'R' && command[1] == 'E') { 

        int s = intconverter(command, 4);

        int l = intconverter(command, 5);

        input = REVSL(input,s,l);

        cout << "rev : "<<input<<"\n"; 

     };

     

     if (command[0] == 'M' && command[1] == 'C') { 

        int s = intconverter(command, 3);

        int l = intconverter(command, 4);

        int t = intconverter(command, 5);

        char ll = command[6];

        

        input = MCSLXD(input,s,l,t,ll);

        cout << "mc  : "<<input<<"\n"; 

     };

     

     if (command[0] != 'R' && command[0] != 'L' && command[0] != 'M') { 

        cout << "Invalid command. Use LS, RS, LC, RC, MC, or REV."<<"\n"; 

     };

     

     }

     

}

     system("PAUSE");

     return EXIT_SUCCESS;

};