Cod sursă (job #97905)

Utilizator avatar cstefan Constantin Stefan cstefan IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 1,77 kb
Rundă Tema 10 clasele 9-10 2014/15 Status evaluat
Dată 13 dec. 2014 23:19:24 Scor 0
//Iisuse miluieste - ma
#include<fstream>
#include<cctype>
#define GOD 100000
#define Saint -7

using namespace std;

long int a[ GOD ] , i , k , p , r , contor = 0 , gasit ;
char next;
//Doamne ajuta!
int searchopen( long int v[ ] , long int n )
{
i = n - 2;
gasit = 0;
while( ( i >= 0 ) && ( !gasit ) )
     {
      if ( !v[ i ] )
          gasit = 1;
      i --;
      }
return ( i + 1 );
}
//Doamne ajuta!
int searchclose( long int v[ ] , long int n )
{
i = 0;
gasit = 0;
while( ( i <= n ) && ( !gasit ) )
      {
       if( v[ i ] == -1 )
    	  gasit = 1;
       i ++;
       }
return ( i - 1 );
}
//Doamne ajuta!
int main()
{
ifstream f("bizar.in");
ofstream g("bizar.out");
i = 0;
while( !f.eof() )
      {
       f>>next;
       if( !isspace( next ) )
	  {
 	   if( isdigit( next ) )
	     {
              r = 0;
 	      while( isdigit( next ) )			
   	           {
                    r = r * 10 + ( next - '0' );
 		    f>>next;
		    }
              a[ i ] = r;
	      i ++;
	      }
           if( next == '(' )
              {
               a[ i ] = 0 ;
	       i ++;
	       contor ++;
	       }
	   if( next == ')'  )
	      {
               a[ i ] = -1;
 	       i ++;
	       }
            }
         }
while( contor )
     {
      k = searchclose( a , i - 1 );			
      p = searchopen ( a , k );
      a[ p - 1 ] = a[ a[ p - 1 ] %  ( k - p - 1 ) + p ];
      for( r = p ; r <= k ; r ++ )
          a[ r ] = Saint;
      gasit = 0;
      for( r = 0 ; r < i ; r ++ )
          {
 	   if ( a[ r ] != Saint )
               a[ gasit ] = a[ r ];
           gasit ++;
           }
       i = gasit;
       contor --;
       }
g<<a[ 0 ];
f.close();
g.close();
return 0;
//Doamne ajuta!
}