Pagini recente »
Istoria paginii runda/nu_este_greu
|
Cod sursă (job #386461)
|
concurs_5_usor
|
Cod sursă (job #443939)
|
Cod sursă (job #97254)
Cod sursă (job
#97254)
#include <cstdio>
using namespace std;
const int MAXSIR = 100001 ;
char sir[MAXSIR] ;
int mstivoasa[1001][1001] ;
int nivel = 1 ;
void citire()
{
freopen("bizar.in","r",stdin);
freopen("bizar.out","w",stdout);
gets(sir) ;
}
int calcul()
{
if( mstivoasa[nivel - 1][mstivoasa[nivel - 1][0]] % mstivoasa[nivel][0] == 0 )
return mstivoasa[nivel][mstivoasa[nivel][0]] ;
return mstivoasa[nivel][mstivoasa[nivel - 1][mstivoasa[nivel - 1][0]] % mstivoasa[nivel][0]] ;
}
void prelucrare()
{
int nr = 0 ;
for ( int i = 0 ; sir[i] != 0 ; i++ )
{
if ( sir[i] == ' ' ) continue;
if ( sir[i] >= '0' && sir[i] <= '9' )
{
nr = nr * 10 + sir[i] - '0' ;
}
if ( sir[i] == '(' )
{
if ( nr != 0 )
mstivoasa[nivel][++mstivoasa[nivel][0]] = nr ;
nr = 0 ;
nivel++;
mstivoasa[nivel][0] = 0 ;
}
if ( sir[i] == ',' )
{
if ( nr != 0 )
mstivoasa[nivel][++mstivoasa[nivel][0]] = nr ;
nr = 0 ;
}
if ( sir[i] == ')' )
{
if ( nr != 0 )
mstivoasa[nivel][++mstivoasa[nivel][0]] = nr ;
mstivoasa[nivel - 1 ][mstivoasa[nivel - 1 ][0]] = calcul();
nivel--;
nr = 0 ;
}
}
}
int main()
{
citire();
prelucrare();
printf("%d\n",mstivoasa[1][1]);
}