首页 > 代码库 > HDU 4891
HDU 4891
一道简单的模拟题
需要要匹配{} 和 $$ 符里面的东西即可
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler#include <stdio.h>#include <iostream>#include <cstring>#include <cmath>#include <stack>#include <queue>#include <vector>#include <algorithm>#define ll long long#define Max(a,b) (((a) > (b)) ? (a) : (b))#define Min(a,b) (((a) < (b)) ? (a) : (b))#define Abs(x) (((x) > 0) ? (x) : (-(x)))using namespace std;const int INF = 0x3f3f3f3f;char a[3000000];ll flag1, flag2;ll flag1_num, flag2_num;ll ans;bool ff;void init(){ flag1 = flag2 = 0; flag1_num = flag2_num = ans = 1; ff = false;}int main(){ ll i, j, k, t, m, n; while(cin >> n){ getchar(); init(); for(k = 0; k < n; ++k){ gets(a); ll len = strlen(a); for(i = 0; i < len; ++i){ if(a[i] == ‘{‘){ flag1 = 1; } else if(a[i] == ‘}‘){ flag1 = 0; ans *= flag1_num; flag1_num = 1; } else if(a[i] == ‘$‘ && !flag2){ flag2 = 1; } else if(a[i] == ‘$‘ && flag2){ flag2 = 0; } else if(a[i] == ‘|‘ && flag1){ ++flag1_num; } else if(a[i] == ‘ ‘ && flag2){ ++flag2_num; } else{ flag2_num = 1; } if(a[i] == ‘ ‘ && a[i + 1] != ‘ ‘ && flag2){ ans *= flag2_num; flag2_num = 1; } if(ans > 100000) ff = true; } } if(ff){ printf("doge\n"); } else{ cout << ans << endl; } } return 0;}
HDU 4891
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。