Advertisement
DMG

Artimeticki izraz (z4)

DMG
Apr 16th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. main()
  4. {
  5.       string s;
  6.       int a=0, b=0, c=0, d=0;
  7.       bool p = true;
  8.      
  9.       cin >> s;
  10.      
  11.       for (int i=0; i<s.length(); i++)
  12.       if (s[i]=='{')
  13.          {
  14.          int j=i;
  15.          while (j<s.length() && s[j]!='}')
  16.              {
  17.                  if(s[j]=='(')
  18.                     a++;
  19.                  if(s[j]==')')
  20.                     b++;
  21.                  if(s[j]=='[')
  22.                     c++;
  23.                  if(s[j]==']')
  24.                     d++;
  25.                    
  26.                  if (s[j]=='}')
  27.                     i=j;
  28.                    
  29.                  j++;
  30.              }
  31.          }
  32.          
  33.       if (a!=b || c!=d)
  34.          p = false;
  35.          
  36.       if (p==true)
  37.       {
  38.             a = 0; b = 0; c = 0; d = 0;
  39.             for (int i=0; i<s.length(); i++)
  40.               if (s[i]=='[')
  41.                  {
  42.                  int j=i;
  43.                  while (j<s.length() && s[j]!=']')
  44.                      {
  45.                          if(s[j]=='(')
  46.                             a++;
  47.                          if(s[j]==')')
  48.                             b++;
  49.                            
  50.                          if (s[j]==']')
  51.                             i=j;
  52.                            
  53.                          j++;
  54.                      }
  55.                  }
  56.                  
  57.                  if (a!=b)
  58.                     p = false;    
  59.                    
  60.                  if (p==true)
  61.                  {
  62.                              for (int i=0; i<s.length(); i++)
  63.                                  if (s[i]=='(')
  64.                                     c++;
  65.                                  else if (s[i]==')')
  66.                                     d++;
  67.                                    
  68.                               if (c!=d)
  69.                               cout << "0" << endl;
  70.                               else cout << "1" << endl;
  71.                  }
  72.                  else cout << "0" << endl;
  73.       }
  74.       else cout << "0" << endl;
  75.  
  76.       system ("PAUSE");
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement