Cod sursa(job #849438)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 6 ianuarie 2013 22:19:08
Problema Shop Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include<stdio.h>
#include<string.h>
char a [ 60007 ] ;
long n , ok , nr , nr2 , num2 , num , t ;
int main ( )
{
    freopen ( "editor.in" , "r" , stdin ) ;
    freopen ( "editor.out" , "w" , stdout ) ;
    scanf ( "%ld\n" , & t ) ;
    for ( ; t > 0 ; -- t )
    {
        memset ( a , 0 , sizeof ( a ) ) ;
        gets ( a ) ;
        n = strlen ( a ) - 1 ;
        for ( long i = 0 ; i <= n ; ++ i )
            if ( a [ i ] == '*' )
                for ( long j = i ; j >= 0 ; -- j )
                    if ( a [ j ] != '*' && a [ j ] !=' ' )
                    {
                        a [ j ] = ' ' ;
                        break ;
                    }
        ok = nr2 = num2 = nr = num = 0 ;
        for ( long i = 0 ; i <= n && ok == 0 ; ++ i )
        {
            if ( a [ i ] == '(' )
                nr ++ ;
            if ( a [ i ] == ')' )
                nr2 ++ ;
            if ( a [ i ] == '[' )
                num ++ ;
            if ( a [ i ] == ']' )
                num2 ++ ;
            if ( nr < nr2 || num < num2 )
                ok = 1 ;
        }
        if ( ok == 0 && nr == nr2 && num == num2 )
            printf ( ":)\n" ) ;
        else
            printf ( ":(\n" ) ;
    }
    return 0 ;
}