#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int input[6000];
int n;
int stack[6000];
int stack_v[6000];
bool deal( )
{
int top = 0;
int topv = 0;
for( int i = 0; i < n; i++ )
{
if( input[i] < 0 )
{
if( top == 0 )
{
stack[top++] = input[i];
stack_v[topv++] = input[i];
}
else
{
if( stack_v[top-1] < input[i] )
{
stack[top++] = input[i];
stack_v[topv++] = input[i];
}
else
false;
}
}
else if( input[i] > 0 )
{
if( stack[top-1] + input[i] == 0 )
{
top--;
topv--;
if( input[i+1] < 0 )
{
stack_v[top-1] += input[i];
}
}
else
return false;
}
else
return false;
}
if( top == 0 ) return true;
else return false;
}
int main()
{
int i; int end; char ch;
while(1)
{
i=end=0;
while(1)
{
if(scanf("%d",&input[i])==EOF) {end=1; break;} i++;
ch=getchar(); if(ch=='\n') break;
}
if(end) return 0;
n=i;
if(deal()) printf(":-) Matrioshka!\n");
else printf(":-( Try again.\n");
}
return 0;
}
uva 11111
最新推荐文章于 2017-09-03 17:56:21 发布