#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int stk[10000010], s[10000010];
int main()
{
int a, error = 0, top = 0;
char b;
while(scanf("%d%c", &a, &b) == 2)
{
if(b != '\n')
{
if(!error)
{
if(a < 0)
{
top++;
stk[top] = -a;
s[top] = -a;
if(top-1 > 0)
{
s[--top] += a;
if(s[top] <= 0) error = 1;
top++;
}
}
else
{
if(a != stk[top]) error = 1;
else top--;
}
}
}
else
{
if(!error)
{
if(a < 0)
error = 1;
else
{
if(a != stk[top]) error = 1;
else if(s[top-1]) error = 1;
}
}
if(error) cout << ":-( Try again." << endl;
else cout << ":-) Matrioshka!" << endl;
error = 0;
top = 0;
}
}
return 0;
}
uva 11111 - Generalized Matrioshkas
最新推荐文章于 2017-09-03 17:56:21 发布