11111UVa俄罗斯套娃

来源:互联网 发布:机枪升级数据 编辑:程序博客网 时间:2024/04/29 17:13


#include<stdio.h>#include<string.h>int stack[10000];int sum[10000];int main(){//freopen("input.txt","r",stdin);int top = 0; //count from 1while(true){top = 0;memset(sum, 0, sizeof(sum) );if(scanf("%d", &stack[++top]) != 1) break;bool ok = true;while(getchar() != '\n'){int temp;scanf("%d", &temp);if(ok == false) continue;if(temp <0){stack[++top] = temp;    sum[top-1] += -(temp);}else if(temp > 0){if(-temp != stack[top] ){ok = false;}else{if(sum[top] >= - stack[top]){ok = false;}else{sum[top] =0;top--;}}}}if(top == 0 && ok)printf(":-) Matrioshka!\n");elseprintf(":-( Try again.\n");}}


0 0
原创粉丝点击