跳到正文

题解

题解[AT4992] ABC

Shellmega约 1 分钟
原文
文章信息与版本

文章信息

发布
2021年3月21日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

题意简述:

略。见题目。


思路:

显然单独的C与B是没有用处的。所以我们只保留BC与A。

于是我们可以记录A的个数,如果遇到BC就把结果加上记录的值。如果遇到单独的B或C就把A的个数清零。


code:

C++
#include<iostream>
#include<string>
#define int long long
using namespace std;
signed main(){
   string c;
   cin>>c;
   int tot=0,ans=0;
   for(int i=0;i<c.size();i++){
      if(c[i]=='A')tot++;
      else if(c[i]=='B'){
         if(i+1<c.size()&&c[i+1]=='C'){
            ans+=tot;i++;
         }
         else
            tot=0;
      }
      else
         tot=0;
   }
   cout<<ans<<endl;
   return 0;
}

tips:

  1. 不开long long见祖宗
  2. 注意下标
原文