A. The Alphabet Sticker 思维

When we were kids, we used to play with some stickers where these stickers contain some (but not necessarily all) lower case English alphabet letters.
Each sticker contains some letters arranged in a single row, where all occurrences of the same letter are adjacent to each other. A sticker can be represented as a string of characters, for example the following are valid stickers’ representations: “aabcc”, “ccccab” and “mmaw”. And the following are not valid (because not all occurrences of the same letter are adjacent to each other): “abacc”, “cccabc” and “mawm”.
Now we found some stickers with some missing letters, but we are sure that all missing letters belong to the visible letters set (that is, for every missing letter, there is at least one visible letter that matches the missing one). In this problem a question mark letter represents a missing letter. Given some stickers’ representations with zero or more missing letters, your task is to count the number of possible original configurations for each sticker.
For example, this sticker “aa??bb” with missing letters could have been one of the following original stickers“aaaabb”, “aaabbb” or “aabbbb”. But it could not have been any of the following original stickers “aababb”(it is invalid sticker) and “aaccbb” (because the letter ‘c’ did not appear in the given configuration).
Input
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Followed by the test cases, each test case is described in one line which contains a non-empty string which consists of up to 10,000 letters, each letter is either a lowercase English letter (from ‘a’ to ‘z’) or a question mark (‘?’). This string represents a sticker configuration which contains zero or more question marks, it will also contain at least one letter which is not a question mark and there will be at least one valid original configuration for it.
Output
For each test case, print a single line which contains a single integer representing the number of possible original configurations for the sticker, since the result may be very large, print it modulo 1,000,000,007(10^9 + 7).

4
aa??bb
aaccbb
?a?
a??a
3
1
1
1

题目:判断合法的种类数,如果相同字母在一块,则合法
思路:
当问号在两边或者没有的时候自然是一种;
当问号在中间:
1.如果两边相同,一种
2.如果不同:
假设是a和b,如果有两个问号 aa bb ab,如果有三个问号 aaa aab abb bbb,如果有四个问号,
aaaa aaab aabb abbb bbbb。由此可见其规律,种类=长度+1;
当问号分为几部分,则相乘;
代码:

#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<string.h>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
int t,n; 
int main()
{
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		ll ans=1;
		int a=0,b=s.size()-1;
		while(s[a]=='?')a++;
		while(s[b]=='?')b--;
		for(int i=a;i<=b;i++)
		{
			if(s[i]=='?')
			{
				int t=i;
				while(s[t]=='?')
				{
					t++;
				}
				if(s[i-1]!=s[t])ans=(ans*((t-i+1)%mod))%mod;
				i=t;
			}
		}
		cout<<ans<<'\n';
	}
    return 0; 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

容艾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值