
這道題還是比較水的
列舉
i
i
i,暴力找到
i
i
i 之后第一個出現的
b
e
a
r
bear
bear 的位置,
然后直接將后面所有字母個數累加即可,
誰能告訴我 O ( n ) O(n) O(n) 的方法怎么做!!!私我!!!
代碼:
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long vis[100010],ans;
string s;
int main()
{
cin>>s;
for(int i=0; i<=s.size()-1; i++)
for(int j=i; j<=s.size()-1; j++)
if(s[j]=='b'&&s[j+1]=='e'&&s[j+2]=='a'&&s[j+3]=='r')
{
ans=ans+((s.size()-1)-(j+3))+1;
break;
}
cout<<ans;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/26957.html
標籤:其他
上一篇:鴻蒙OS代碼正式開源
