hdu 4891 模拟水题

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 100005

int 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;
}


转载于:https://www.cnblogs.com/zibaohun/p/4046764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值