Cod sursă (job #98032)

Utilizator avatar cstefan Constantin Stefan cstefan IP ascuns
Problemă Bizar (clasele 9-10) Compilator cpp | 1,64 kb
Rundă Tema 10 clasele 9-10 2014/15 Status evaluat
Dată 14 dec. 2014 16:58:33 Scor 18
//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 ;
 
//Doamne ajuta!
int searchopen( long int v[ ] , long int n )
{
 i = n - 1;
 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");
char next;
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 ++;
	  }
	}
      }
gasit = i ;
 while( gasit > 1 )
       {
	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!
}