O(n)的时间复杂度~~
#include<string.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[1100000];
int main()
{char str[5001];int n,i;while(gets(str)!=NULL){n=strlen(str);for(i=1;i<=n;i++){if(str[i-1]=='F')dp[i]=dp[i-1]+1;else dp[i]=dp[i-1];}for(i=n;i>=1;i--){if(str[i-1]=='B')dp[i]=dp[i];else dp[i]=0;}for(i=1;i<=n;i++)dp[i]+=dp[i-1];int sum=0;for(i=1;i<=n;i++){if(str[i-1]=='I')sum+=dp[i];}cout<<sum<<endl;}return 0;
}