HDU 4891 水

2014 Multi-University Training Contest 3

$$之间每出现连续的n个空格,乘以n+1;

{|}计算|的个数为n,乘以n+1。

#include "stdio.h"
#include "string.h"
char str[1000000000];
int main()
{
    int n,mark,ok,i;
    __int64 ans,pri;
    while (scanf("%d",&n)!=EOF)
    {
        getchar();
        mark=0; pri=1; ans=1; ok=1;
        while (n--)
        {
            gets(str);
            for (i=0;str[i];i++)
            {
                if (str[i]=='{') {mark=1; ans=1;}
                else
                if (str[i]=='}') {mark=0; pri*=ans; ans=1;}
                else
                if (str[i]=='$' && mark==0) { mark=2; ans=1;}
                else
                if (str[i]=='$' && mark==2) { mark=0; pri*=ans; ans=1;}

                if (mark==1 && str[i]=='|') ans++;

                if (mark==2 && str[i]==' ') ans++;

                if (mark==2 && str[i]!=' ') {pri*=ans; ans=1;}
                
                if (pri>100000) {ok=0; pri=0;}
            }
        }
        if (ok==0) printf("doge\n");
        else printf("%I64d\n",pri);
    }
    return 0;
}


你可能感兴趣的:(HDU 4891 水)