Advertisement
KiberInfinity

lab...

Apr 4th, 2011
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4. int proc_S(char*szs, int in, int*pirul, int*ip);
  5. void WriteRules(int*pirul, int*ip, int irule);
  6.  
  7.  
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {    
  10.     int rules[12];
  11.     int N=0;
  12.    
  13.     for (int i=0; i<10; i++) rules[i]=0;
  14.     char *wer="aa+a-";
  15.     int len=strlen(wer)-1;
  16.     int k=proc_S(wer,len,rules,&N);
  17.     //if(k!=-2) for (int i=N-1; i>=0; i--) cout<<rules[i]<<endl;
  18.     if(k!=-2) for (int i=0; i<N; i++) cout<<rules[i]<<endl;
  19.     system("pause");
  20.     return 0;
  21. }
  22.  
  23. int proc_S(char*szs, int in, int*pirul, int*ip){
  24.     int i=-2;
  25.     switch(szs[in]){
  26.     case '+':
  27.         WriteRules(pirul, ip, 1);
  28.         i= proc_S(szs, in-1, pirul, ip);
  29.         if(i==-2) return -2;
  30.         i= proc_S(szs, i, pirul, ip);
  31.         return i;
  32.     case '-':
  33.         WriteRules(pirul, ip, 2);
  34.         i= proc_S(szs, in-1, pirul, ip);
  35.         if(i==-2) return -2;
  36.         i= proc_S(szs, i, pirul, ip);
  37.         return i;
  38.     case 'a':
  39.         WriteRules(pirul, ip, 3);
  40.         return in-1;
  41.     }
  42.     return -2;
  43. }
  44.  
  45.  
  46. void WriteRules(int*pirul, int*ip, int irule){
  47.     pirul[*ip]=irule;
  48.     *ip=*ip+1;
  49.  
  50. }
Advertisement
RAW Paste Data Copied
Advertisement