hdu 4891 模拟水题

来源:互联网 发布:c语言中的关键字有哪些 编辑:程序博客网 时间:2024/05/16 12:28

http://acm.hdu.edu.cn/showproblem.php?pid=4891

给出一个文本,问说有多少种理解方式。
1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数。
2.{}中间,即 | 的个数+1.


就是模拟

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>#include <string>#include <cmath>using namespace std;#define RD(x) scanf("%d",&x)#define RD2(x,y) scanf("%d%d",&x,&y)#define clr0(x) memset(x,0,sizeof(x))typedef long long LL;#define N 100005int n;string x , y;LL check(int l , int r){    LL ans = 1,tmp = 1;    for (int i=l;i<=r;++i){        if (x[i] == ' ')            ++tmp;        else{           ans *= tmp;           tmp = 1;           if (ans > 100000)            return -1;        }    }    return ans;}LL checkk(int l , int r){    LL ans = 1;    for (int i=l;i<=r;++i)        if (x[i] == '|') ++ans;    return ans;}void work(){     getchar();     x = "";     while (n--){           getline(cin,y);           x += y;     }     int m = x.size();     LL ans = 1 , now;     for(int i = 0;i < m;){           while (x[i] != '$' && x[i] != '{' && i < m) ++i;           if (i == m) break;           int j = i+1;           if (x[i] == '$'){                while (x[j] != '$') ++j;                now = check(i,j);           } else {              while (x[j] != '}') ++j;              now = checkk(i,j);           }           if (now == -1){               puts("doge");               return;           }           ans *= now;           if (ans > 100000){               puts("doge");               return;           }           i = j+1;     }     printf("%I64d\n",ans);}int main(){    while (~RD(n))        work();    return 0;}


0 0
原创粉丝点击