现在的位置: 首页 > 综合 > 正文

HOJ 12822 The Alphabet Sticker

2019年02月12日 ⁄ 综合 ⁄ 共 869字 ⁄ 字号 评论关闭

AC代码:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <assert.h>
#include <algorithm>
#define MAX 1234567890
#define MIN -1234567890
#define exps 1e-8
#define MOD 1000000007

using namespace std;

char* ptr;
char tmp[10008];
char str[10008];
int i, len;

int cnt()
{
        int c = 0;
        while (str[i] == '?')
        {
                c++;
                i++;
        }
        i--;
        return c + 1;
}

int main()
{
        #ifdef BellWind
        freopen("A.in", "r", stdin);
        #endif // BellWind
        int t;
        scanf("%d", &t);

        for (int k = 0; k < t; k++)
        {
                long long ans = 1;
                memset(str, 0, sizeof(str));

                scanf("%s\n", tmp);
                ptr = tmp;
                int tlen = strlen(tmp);

                int l = 0;
                while (tmp[l] == '?') {l++;}
                int r = tlen - 1;
                while (tmp[r] == '?') {r--;}
                int j;
                for (j = l, i = 0; j <= r; i++, j++) str[i] = tmp[j];
                str[i] = '\0';
                len = strlen(str);
//                cout << len << endl;
//                printf("%s\n", str);

                for (i = 0; i < len; i++)
                {
                        if(str[i] == '?')
                        {
                                char ch1 = str[i-1];
                                int tmpn = cnt();
                                char ch2 = str[i+1];
                                if (ch1 != ch2) ans = ((ans % MOD) * (tmpn % MOD)) % MOD;
                        }
                }
                printf("%d\n", ans);
        }

        return 0;
}

抱歉!评论已关闭.