Advertisement
dllbridge

Untitled

Feb 26th, 2025
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.47 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include  <stdio.h>
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10. char sz[199] = "7+4/3";
  11.  
  12. int nArr[11],
  13.      nOp[11];
  14.  
  15. int x = 0,
  16.     y = 0;  //  Счётчик операторов
  17.  
  18. int  analis(char);
  19. void nonitor();
  20. void nonitor_Op();
  21. void foo();
  22.  
  23. /////////////////////////////////////////////////////////////scanf("%s", sz); /
  24. int main()
  25. {
  26.  
  27.  
  28.    
  29.  
  30.    
  31.  
  32.     setlocale(LC_ALL, "rus");
  33.    // cout << "Введите арифметическое выражение: "; cin >> sz;
  34.    
  35.    
  36.     cout << "   sz = " << sz << endl;
  37.  
  38.     for(int i = 0; sz[i] != 0; i++)
  39.     {
  40.        cout << "anlis = " << analis(sz[i]) << endl;    
  41.    
  42.     }
  43.    
  44.    
  45.     nonitor();
  46.    
  47.     nonitor_Op();
  48.    
  49.     foo();
  50.    
  51. return 0;
  52. }
  53.  
  54. /////////////////////////////////////////////////////
  55. void foo()
  56. {
  57.      int n = 1;
  58.      
  59.      for(int i = 1; i <= y; i++ )
  60.      {
  61.              
  62.          switch(nOp[i])
  63.          {
  64.             case  1:   cout << nArr[n] <<" + "<< nArr[n+1] <<" = "<<
  65.                                nArr[n] + nArr[n+1] << endl;    
  66.                        
  67.                        break;
  68.                      
  69.  
  70.                        
  71.                                              
  72.          }            
  73.      }    
  74.      
  75. }
  76.  
  77.  
  78.  
  79. /////////////////////////////////////////////////////////////////////
  80. int analis(char c)
  81. {
  82.    
  83.     if(c >= '0')
  84.     if(c <= '9')  
  85.     {
  86.         //nArr[0] ++;
  87.         x ++;
  88.         nArr[ x ] = c - 48;
  89.         return      c - 48;    
  90.     }
  91.    
  92.     switch(c)
  93.     {
  94.         case  '+':   y++;
  95.                     nOp[y] = 1;  break;
  96.                  
  97.         case  '-':   y++;
  98.                     nOp[y] = 2;   break;
  99.                  
  100.         case  '*':   y++;                      
  101.                     nOp[y] = 3; break;
  102.                    
  103.         case  '/':   y++;
  104.                     nOp[y] = 4; break;
  105.                    
  106.                    
  107.         default:    cout << "Error!\n";                                            
  108.     }
  109.    
  110. return -1;    
  111. }
  112.  
  113.  
  114.  
  115. //////////////////////////////////////////////////////////////////////
  116. void nonitor()
  117. {
  118.      for(int i = 1; i <= x; i++ )
  119.      {
  120.      
  121.          cout << nArr[ i ] <<", ";
  122.      }
  123.      
  124.      cout << endl;
  125. }
  126.  
  127.  
  128. //////////////////////////////////////////////////////////////////////
  129. void nonitor_Op()
  130. {
  131.      for(int i = 1; i <= y; i++ )
  132.      {
  133.      
  134.          cout << nOp[ i ] <<", ";
  135.      }
  136.      
  137.      cout << endl;
  138. }
  139.  
  140.  
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement