/*
栈操作,类似括号匹配
*/
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
const int BUFF_SIZE = 100004;
int st[BUFF_SIZE], v[BUFF_SIZE];
int fr;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n;
v[0] = st[0] = 1<<30;
fr = 1;
int ok = 1;
while(scanf("%d", &n) == 1) {
if(ok) {
if(n < 0) {
n = -n;
if(n >= v[fr-1]) {
ok = 0; continue;
}
v[fr-1] -= n;
v[fr] = n;
st[fr++] = n;
}
else if(st[--fr] != n) ok = 0;
}
if(getchar() == '\n') {
if(ok && fr==1) printf(":-) Matrioshka!\n");
else printf(":-( Try again.\n");
v[0] = st[0] = 1<<30;
fr = ok = 1;
continue;
}
}
return 0;
}
UVa 11111 - Generalized Matrioshkas
最新推荐文章于 2021-04-03 00:46:53 发布