Codeforces Round #526 (Div. 2) CodeForces - 1084C

本文介绍了一个关于字符串处理的问题,通过遍历字符串并使用动态更新的方式,计算特定字符序列的组合数量。该算法利用了数学运算和取模操作,避免了大数溢出的问题,展示了高效的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C题

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =1e5+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int main()
{
	int a=0;
    ll sum=1;
    string s; cin>>s;
    for(int i=0;i<s.length();i++)
    {
      if( s[i]=='a' ) a++;
      else if (s[i]=='b'){
        sum=(sum*(a+1))%mod;
        a=0;
        while(s[i]!='a'&&i<s.length())
          i++;
        i--;
      }
    }
    sum*=(a+1);
    cout<<(sum-1)%mod<<endl;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值