【题解】 AGC029-A Irreversible operation

传送门


定位:思维好题。

考虑无论如何每一个W都会和前面的B在一起交换一次,所以直接求和就好了。

注意long long的使用。

#include<stdio.h>
#include<string.h>
char s[200010];
long long ans,b;
int main(){
	scanf("%s",s);int n=strlen(s);
	for(int i=0;i<n;i++)
		if(s[i]=='B')b++;
		else ans+=b;
	printf("%lld\n",ans);
	return 0;
}
posted @ 2018-12-17 10:40  cjgjh  阅读(211)  评论(0编辑  收藏  举报