SHARE
TWEET

ab.cpp

a guest Aug 24th, 2014 263 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int Num_char = 0;
  9. int Position = 0;
  10. int NewPosition;
  11.  
  12. int Character;
  13. string Program[10000];
  14.  
  15. string Result;
  16. int Register1 = 0;
  17. int Register2 = 0;
  18. int Register3 = 0;
  19. int Register4[] = { 0, 0 };
  20. int Mode = 0;
  21. int Memory[1024];
  22. int Temp;
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     FILE * FileInd;
  27.    
  28.     FileInd = fopen(argv[1],"r");
  29.    
  30.     do {
  31.         Character = getc(FileInd);
  32.         Program[Num_char] = Character;
  33.         Num_char ++;
  34.        
  35.         } while ( Character != EOF );
  36.    
  37.     fclose(FileInd);
  38.    
  39.     do {
  40.         NewPosition = Position;
  41.  
  42.         if ( Program[Position] == "a" ) { Register1 += 1 ;}
  43.         if ( Program[Position] == "b" ) { Register1 -= 1 ;}
  44.         if ( Program[Position] == "c" ) { Register1 += 10 ;}
  45.         if ( Program[Position] == "d" ) { Register1 -= 10 ;}
  46.         if ( Program[Position] == "e" ) { Register1 += 100 ;}
  47.         if ( Program[Position] == "f" ) { Register1 -= 100 ;}
  48.         if ( Program[Position] == "g" ) { Register2 += 1 ;}
  49.         if ( Program[Position] == "h" ) { Register2 -= 1 ;}
  50.         if ( Program[Position] == "i" ) { Register2 += 10 ;}
  51.         if ( Program[Position] == "j" ) { Register2 -= 10 ;}
  52.         if ( Program[Position] == "k" ) { Register2 += 100 ;}
  53.         if ( Program[Position] == "l" ) { Register2 -= 100 ;}
  54.         if ( Program[Position] == "m" ) { Register3 = !Register1 ;}
  55.         if ( Program[Position] == "n" ) { Register3 = !Register2 ;}
  56.         if ( Program[Position] == "o" ) { Register3 = Register1 and Register2 ;}
  57.         if ( Program[Position] == "p" ) { Register3 = Register1 or Register2 ;}
  58.         if ( Program[Position] == "q" ) { Register3 = Register1 xor Register2 ;}
  59.         if ( Program[Position] == "q" ) { Register3 = Register1 xor Register2 ;}
  60.         if ( Program[Position] == "r" ) { Register3 = Register1 + Register2 ;}
  61.         if ( Program[Position] == "s" ) { Register3 = Register1 - Register2 ;}
  62.         if ( Program[Position] == "t" ) { Register3 = Register1 * Register2 ;}
  63.         if ( Program[Position] == "u" ) { Register3 = Register1 / Register2 ;}
  64.         if ( Program[Position] == "v" ) { Register3 = Register1 % Register2 ;}
  65.         if ( Program[Position] == "w" ) { Register3 = Register1 ^ Register2 ;}
  66.         if ( Program[Position] == "x" ) { Register1 = 0 ;}
  67.         if ( Program[Position] == "y" ) { Register2 = 0 ;}
  68.         if ( Program[Position] == "z" ) { Register3 = 0 ;}
  69.         if ( Program[Position] == "A" ) { Register2 = Register1 ;}
  70.         if ( Program[Position] == "B" ) { Register1 = Register2 ;}
  71.         if ( Program[Position] == "C" ) { Register3 = Register1 ;}
  72.         if ( Program[Position] == "D" ) { Register3 = Register2 ;}
  73.         if ( Program[Position] == "E" ) { Register1 = Register3 ;}
  74.         if ( Program[Position] == "F" ) { Register2 = Register3 ;}
  75.         if ( Program[Position] == "G" ) { Register1 = Memory[Register4[0]] ;}
  76.         if ( Program[Position] == "H" ) { Register2 = Memory[Register4[0]] ;}
  77.         if ( Program[Position] == "I" ) { Memory[Register4[0]] = Register3 ;}
  78.         if ( Program[Position] == "J" ) { if (( Temp = getchar()) != EOF ) Register1 = Temp ;}
  79.         if ( Program[Position] == "K" ) { if (( Temp = getchar()) != EOF ) Register2 = Temp ;}
  80.         if ( Program[Position] == "L" ) { cout << char(Register3) ;}
  81.         if ( Program[Position] == "M" ) { cout << int(Register3) ;}
  82.         if ( Program[Position] == "N" ) { if ( Register1 == Register2 ) NewPosition = Register4[1];}
  83.         if ( Program[Position] == "O" ) { if ( Register1 != Register2 ) NewPosition = Register4[1];}
  84.         if ( Program[Position] == "P" ) { if ( Register1 >= Register2 ) NewPosition = Register4[1];}
  85.         if ( Program[Position] == "Q" ) { if ( Register1 <= Register2 ) NewPosition = Register4[1];}
  86.         if ( Program[Position] == "R" ) { if ( Register3 == 0 ) NewPosition = Register4[1] - 1;}
  87.         if ( Program[Position] == "S" ) { Register4[Mode] += 1 ;}
  88.         if ( Program[Position] == "T" ) { Register4[Mode] -= 1 ;}
  89.         if ( Program[Position] == "U" ) { Register4[Mode] += 10 ;}
  90.         if ( Program[Position] == "V" ) { Register4[Mode] -= 10 ;}
  91.         if ( Program[Position] == "W" ) { Register4[Mode] += 100 ;}
  92.         if ( Program[Position] == "X" ) { Register4[Mode] -= 100 ;}
  93.         if ( Program[Position] == "Y" ) { Register4[Mode] = 0 ;}
  94.         if ( Program[Position] == "Z" ) { Mode = ( Mode + 1 ) % 2 ;}
  95.        
  96.         Position = (Position == NewPosition) ? Position + 1 : NewPosition;
  97.         } while ( Position <= Num_char );
  98.        
  99.     return ( 1 );
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top